File tree Expand file tree Collapse file tree 2 files changed +12
-12
lines changed Expand file tree Collapse file tree 2 files changed +12
-12
lines changed Original file line number Diff line number Diff line change @@ -3903,6 +3903,18 @@ bool ConstraintSystem::generateConstraints(
3903
3903
shrink (expr);
3904
3904
target.setExpr (expr);
3905
3905
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
+
3906
3918
// Generate constraints for the main system.
3907
3919
expr = generateConstraints (expr, target.getDeclContext ());
3908
3920
if (!expr)
Original file line number Diff line number Diff line change @@ -2085,18 +2085,6 @@ TypeChecker::typeCheckExpression(
2085
2085
if (options.contains (TypeCheckExprFlags::AllowUnresolvedTypeVariables))
2086
2086
allowFreeTypeVariables = FreeTypeVariableBinding::UnresolvedType;
2087
2087
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
-
2100
2088
// Attempt to solve the constraint system.
2101
2089
auto viable = cs.solve (target, listener, allowFreeTypeVariables);
2102
2090
if (!viable) {
You can’t perform that action at this time.
0 commit comments