@@ -2107,6 +2107,7 @@ TypeChecker::typeCheckExpression(
2107
2107
target.setExpr (expr);
2108
2108
return None;
2109
2109
}
2110
+ target.setExpr (expr);
2110
2111
2111
2112
// Construct a constraint system from this expression.
2112
2113
ConstraintSystemOptions csOptions = ConstraintSystemFlags::AllowFixes;
@@ -2127,46 +2128,34 @@ TypeChecker::typeCheckExpression(
2127
2128
// diagnostics and is a hint for various performance optimizations.
2128
2129
// FIXME: Look through LoadExpr. This is an egregious hack due to the
2129
2130
// way typeCheckExprIndependently works.
2130
- TypeLoc convertType = target.getExprConversionTypeLoc ();
2131
2131
Expr *contextualTypeExpr = expr;
2132
2132
if (auto loadExpr = dyn_cast_or_null<LoadExpr>(contextualTypeExpr))
2133
2133
contextualTypeExpr = loadExpr->getSubExpr ();
2134
2134
cs.setContextualType (
2135
- contextualTypeExpr, convertType,
2135
+ contextualTypeExpr,
2136
+ target.getExprConversionTypeLoc (),
2136
2137
target.getExprContextualTypePurpose (),
2137
2138
target.infersOpaqueReturnType ());
2138
2139
2139
- // If the convertType is *only* provided for that hint, then null it out so
2140
- // that we don't later treat it as an actual conversion constraint.
2141
- if (target.contextualTypeIsOnlyAHint ())
2142
- convertType = TypeLoc ();
2143
-
2144
2140
// If the client can handle unresolved type variables, leave them in the
2145
2141
// system.
2146
2142
auto allowFreeTypeVariables = FreeTypeVariableBinding::Disallow;
2147
2143
if (options.contains (TypeCheckExprFlags::AllowUnresolvedTypeVariables))
2148
2144
allowFreeTypeVariables = FreeTypeVariableBinding::UnresolvedType;
2149
2145
2150
- Type convertTo = convertType.getType ();
2151
-
2146
+ // If the target requires an optional of some type, form a new appropriate
2147
+ // type variable and update the target's type with an optional of that
2148
+ // type variable.
2152
2149
if (target.isOptionalSomePatternInit ()) {
2153
- assert (!convertTo && " convertType and type check options conflict" );
2150
+ assert (!target. getExprConversionType () && " convertType and type check options conflict" );
2154
2151
auto *convertTypeLocator =
2155
2152
cs.getConstraintLocator (expr, LocatorPathElt::ContextualType ());
2156
2153
Type var = cs.createTypeVariable (convertTypeLocator, TVO_CanBindToNoEscape);
2157
- convertTo = getOptionalType (expr->getLoc (), var);
2158
- } else if (target.getExprContextualTypePurpose ()
2159
- == CTP_AutoclosureDefaultParameter) {
2160
- // FIXME: Hack around the convertTo adjustment below, which we want to
2161
- // eliminate.
2162
- convertTo = Type (target.getAsAutoclosureParamType ());
2154
+ target.setExprConversionType (getOptionalType (expr->getLoc (), var));
2163
2155
}
2164
2156
2165
2157
// Attempt to solve the constraint system.
2166
- SolutionApplicationTarget innerTarget (
2167
- expr, dc, target.getExprContextualTypePurpose (), convertTo,
2168
- target.isDiscardedExpr ());
2169
- auto viable = cs.solve (innerTarget, listener, allowFreeTypeVariables);
2158
+ auto viable = cs.solve (target, listener, allowFreeTypeVariables);
2170
2159
if (!viable) {
2171
2160
target.setExpr (expr);
2172
2161
return None;
@@ -2177,7 +2166,8 @@ TypeChecker::typeCheckExpression(
2177
2166
// because they will leak out into arbitrary places in the resultant AST.
2178
2167
if (options.contains (TypeCheckExprFlags::AllowUnresolvedTypeVariables) &&
2179
2168
(viable->size () != 1 ||
2180
- (convertType.getType () && convertType.getType ()->hasUnresolvedType ()))) {
2169
+ (target.getExprConversionTypeForConstraint () &&
2170
+ target.getExprConversionTypeForConstraint ()->hasUnresolvedType ()))) {
2181
2171
// FIXME: This hack should only be needed for CSDiag.
2182
2172
unresolvedTypeExprs = true ;
2183
2173
return target;
@@ -2191,10 +2181,6 @@ TypeChecker::typeCheckExpression(
2191
2181
// Apply the solution to the expression.
2192
2182
bool performingDiagnostics =
2193
2183
options.contains (TypeCheckExprFlags::SubExpressionDiagnostics);
2194
- // FIXME: HACK! Copy over the inner target's expression info.
2195
- target.setExpr (innerTarget.getAsExpr ());
2196
- if (convertTo.isNull ())
2197
- target.setExprConversionType (convertTo);
2198
2184
auto resultTarget = cs.applySolution (solution, target, performingDiagnostics);
2199
2185
if (!resultTarget) {
2200
2186
// Failure already diagnosed, above, as part of applying the solution.
0 commit comments