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