@@ -2199,62 +2199,26 @@ namespace {
2199
2199
return getTypeForPattern (cast<VarPattern>(pattern)->getSubPattern (),
2200
2200
locator);
2201
2201
case PatternKind::Any: {
2202
- // If we have a type from an initializer expression, and that
2203
- // expression does not produce an InOut type, use it. This
2204
- // will avoid exponential typecheck behavior in the case of
2205
- // tuples, nested arrays, and dictionary literals.
2206
- //
2207
- // Otherwise, create a new type variable.
2208
- if (auto boundExpr = locator.trySimplifyToExpr ()) {
2209
- if (!boundExpr->isSemanticallyInOutExpr ())
2210
- return CS.getType (boundExpr)->getRValueType ();
2211
- }
2212
-
2213
2202
return CS.createTypeVariable (CS.getConstraintLocator (locator),
2214
2203
TVO_CanBindToNoEscape);
2215
2204
}
2216
2205
2217
2206
case PatternKind::Named: {
2218
2207
auto var = cast<NamedPattern>(pattern)->getDecl ();
2219
2208
2220
- // If we have a type from an initializer expression, and that
2221
- // expression does not produce an InOut type, use it. This
2222
- // will avoid exponential typecheck behavior in the case of
2223
- // tuples, nested arrays, and dictionary literals.
2224
- //
2225
- // FIXME: This should be handled in the solver, not here.
2226
- //
2227
- // Otherwise, create a new type variable.
2228
- auto ty = Type ();
2229
- if (!var->hasNonPatternBindingInit () &&
2230
- !var->hasAttachedPropertyWrapper ()) {
2231
- if (auto boundExpr = locator.trySimplifyToExpr ()) {
2232
- if (!boundExpr->isSemanticallyInOutExpr ())
2233
- ty = CS.getType (boundExpr)->getRValueType ();
2234
- }
2235
- }
2209
+ Type varType = CS.createTypeVariable (
2210
+ CS.getConstraintLocator (locator), TVO_CanBindToNoEscape);
2236
2211
2237
2212
auto ROK = ReferenceOwnership::Strong;
2238
2213
if (auto *OA = var->getAttrs ().getAttribute <ReferenceOwnershipAttr>())
2239
2214
ROK = OA->get ();
2240
-
2241
2215
switch (optionalityOf (ROK)) {
2242
2216
case ReferenceOwnershipOptionality::Required:
2243
- if (ty && ty->getOptionalObjectType ())
2244
- return ty; // Already Optional<T>.
2245
- // Create a fresh type variable to handle overloaded expressions.
2246
- if (!ty || ty->is <TypeVariableType>())
2247
- ty = CS.createTypeVariable (CS.getConstraintLocator (locator),
2248
- TVO_CanBindToNoEscape);
2249
- return TypeChecker::getOptionalType (var->getLoc (), ty);
2217
+ return TypeChecker::getOptionalType (var->getLoc (), varType);
2250
2218
case ReferenceOwnershipOptionality::Allowed:
2251
2219
case ReferenceOwnershipOptionality::Disallowed:
2252
- break ;
2220
+ return varType ;
2253
2221
}
2254
- if (ty)
2255
- return ty;
2256
- return CS.createTypeVariable (CS.getConstraintLocator (locator),
2257
- TVO_CanBindToNoEscape);
2258
2222
}
2259
2223
2260
2224
case PatternKind::Typed: {
0 commit comments