Skip to content

Commit 959c6d5

Browse files
committed
[CSFix] Move type verification out of ExplicitlyConstructRawRepresentable
Do the verification during constraint repair and provide fix itself with raw representative type and its raw value to be used for diagnostics.
1 parent d6bf31c commit 959c6d5

File tree

2 files changed

+25
-18
lines changed

2 files changed

+25
-18
lines changed

lib/Sema/CSFix.cpp

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1144,18 +1144,19 @@ bool ExpandArrayIntoVarargs::diagnose(const Solution &solution,
11441144
return failure.diagnose(asNote);
11451145
}
11461146

1147-
ExplicitlyConstructRawRepresentable *
1148-
ExplicitlyConstructRawRepresentable::attempt(ConstraintSystem &cs, Type argType,
1149-
Type paramType,
1150-
ConstraintLocatorBuilder locator) {
1151-
auto rawRepresentableType = paramType->lookThroughAllOptionalTypes();
1152-
auto valueType = argType->lookThroughAllOptionalTypes();
1153-
1154-
if (isValueOfRawRepresentable(cs, rawRepresentableType, valueType))
1155-
return new (cs.getAllocator()) ExplicitlyConstructRawRepresentable(
1156-
cs, valueType, rawRepresentableType, cs.getConstraintLocator(locator));
1147+
bool ExplicitlyConstructRawRepresentable::diagnose(const Solution &solution,
1148+
bool asNote) const {
1149+
MissingRawRepresentativeInitFailure failure(solution, RawReprType, ValueType,
1150+
getLocator());
1151+
return failure.diagnose(asNote);
1152+
}
11571153

1158-
return nullptr;
1154+
ExplicitlyConstructRawRepresentable *
1155+
ExplicitlyConstructRawRepresentable::create(ConstraintSystem &cs,
1156+
Type rawReprType, Type valueType,
1157+
ConstraintLocator *locator) {
1158+
return new (cs.getAllocator())
1159+
ExplicitlyConstructRawRepresentable(cs, rawReprType, valueType, locator);
11591160
}
11601161

11611162
UseValueTypeOfRawRepresentative *

lib/Sema/CSFix.h

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1594,21 +1594,27 @@ class ExpandArrayIntoVarargs final : public AllowArgumentMismatch {
15941594
ConstraintLocatorBuilder locator);
15951595
};
15961596

1597-
class ExplicitlyConstructRawRepresentable final : public AllowArgumentMismatch {
1598-
ExplicitlyConstructRawRepresentable(ConstraintSystem &cs, Type argType,
1599-
Type paramType,
1597+
class ExplicitlyConstructRawRepresentable final : public ConstraintFix {
1598+
Type RawReprType;
1599+
Type ValueType;
1600+
1601+
ExplicitlyConstructRawRepresentable(ConstraintSystem &cs, Type rawReprType,
1602+
Type valueType,
16001603
ConstraintLocator *locator)
1601-
: AllowArgumentMismatch(cs, FixKind::ExplicitlyConstructRawRepresentable,
1602-
argType, paramType, locator) {}
1604+
: ConstraintFix(cs, FixKind::ExplicitlyConstructRawRepresentable,
1605+
locator),
1606+
RawReprType(rawReprType), ValueType(valueType) {}
16031607

16041608
public:
16051609
std::string getName() const override {
16061610
return "explicitly construct a raw representable type";
16071611
}
16081612

1613+
bool diagnose(const Solution &solution, bool asNote = false) const override;
1614+
16091615
static ExplicitlyConstructRawRepresentable *
1610-
attempt(ConstraintSystem &cs, Type argType, Type paramType,
1611-
ConstraintLocatorBuilder locator);
1616+
create(ConstraintSystem &cs, Type rawTypeRepr, Type valueType,
1617+
ConstraintLocator *locator);
16121618
};
16131619

16141620
class UseValueTypeOfRawRepresentative final : public AllowArgumentMismatch {

0 commit comments

Comments
 (0)