Skip to content

Commit 17e1c91

Browse files
committed
[Constraint system] Sink optional “some” pattern handling into constraint gen
1 parent 4c98b31 commit 17e1c91

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

lib/Sema/CSGen.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3903,6 +3903,18 @@ bool ConstraintSystem::generateConstraints(
39033903
shrink(expr);
39043904
target.setExpr(expr);
39053905

3906+
// If the target requires an optional of some type, form a new appropriate
3907+
// type variable and update the target's type with an optional of that
3908+
// type variable.
3909+
if (target.isOptionalSomePatternInit()) {
3910+
assert(!target.getExprContextualType() &&
3911+
"some pattern cannot have contextual type pre-configured");
3912+
auto *convertTypeLocator =
3913+
getConstraintLocator(expr, LocatorPathElt::ContextualType());
3914+
Type var = createTypeVariable(convertTypeLocator, TVO_CanBindToNoEscape);
3915+
target.setExprConversionType(TypeChecker::getOptionalType(expr->getLoc(), var));
3916+
}
3917+
39063918
// Generate constraints for the main system.
39073919
expr = generateConstraints(expr, target.getDeclContext());
39083920
if (!expr)

lib/Sema/TypeCheckConstraints.cpp

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2085,18 +2085,6 @@ TypeChecker::typeCheckExpression(
20852085
if (options.contains(TypeCheckExprFlags::AllowUnresolvedTypeVariables))
20862086
allowFreeTypeVariables = FreeTypeVariableBinding::UnresolvedType;
20872087

2088-
// If the target requires an optional of some type, form a new appropriate
2089-
// type variable and update the target's type with an optional of that
2090-
// type variable.
2091-
if (target.isOptionalSomePatternInit()) {
2092-
assert(!target.getExprContextualType() &&
2093-
"some pattern cannot have contextual type pre-configured");
2094-
auto *convertTypeLocator =
2095-
cs.getConstraintLocator(expr, LocatorPathElt::ContextualType());
2096-
Type var = cs.createTypeVariable(convertTypeLocator, TVO_CanBindToNoEscape);
2097-
target.setExprConversionType(getOptionalType(expr->getLoc(), var));
2098-
}
2099-
21002088
// Attempt to solve the constraint system.
21012089
auto viable = cs.solve(target, listener, allowFreeTypeVariables);
21022090
if (!viable) {

0 commit comments

Comments
 (0)