@@ -1328,17 +1328,11 @@ namespace {
1328
1328
1329
1329
Type
1330
1330
resolveTypeReferenceInExpression (TypeRepr *repr, TypeResolverContext resCtx,
1331
- OpenUnboundGenericTypeFn unboundTyOpener) {
1332
- if (!unboundTyOpener) {
1333
- unboundTyOpener = [](auto unboundTy) {
1334
- // FIXME: Don't let unbound generic types escape type resolution.
1335
- // For now, just return the unbound generic type.
1336
- return unboundTy;
1337
- };
1338
- }
1339
- const auto result =
1340
- TypeResolution::forContextual (CS.DC , resCtx, unboundTyOpener)
1341
- .resolveType (repr);
1331
+ const ConstraintLocatorBuilder &locator) {
1332
+ // Introduce type variables for unbound generics.
1333
+ const auto opener = OpenUnboundGenericType (CS, locator);
1334
+ const auto result = TypeResolution::forContextual (CS.DC , resCtx, opener)
1335
+ .resolveType (repr);
1342
1336
if (result->hasError ()) {
1343
1337
return Type ();
1344
1338
}
@@ -1364,8 +1358,7 @@ namespace {
1364
1358
auto *repr = E->getTypeRepr ();
1365
1359
assert (repr && " Explicit node has no type repr!" );
1366
1360
type = resolveTypeReferenceInExpression (
1367
- repr, TypeResolverContext::InExpression,
1368
- OpenUnboundGenericType (CS, locator));
1361
+ repr, TypeResolverContext::InExpression, locator);
1369
1362
}
1370
1363
1371
1364
if (!type || type->hasError ()) return Type ();
@@ -2067,10 +2060,8 @@ namespace {
2067
2060
const auto resolvedTy = resolveTypeReferenceInExpression (
2068
2061
closure->getExplicitResultTypeRepr (),
2069
2062
TypeResolverContext::InExpression,
2070
- // Introduce type variables for unbound generics.
2071
- OpenUnboundGenericType (
2072
- CS, CS.getConstraintLocator (
2073
- closure, ConstraintLocator::ClosureResult)));
2063
+ CS.getConstraintLocator (closure,
2064
+ ConstraintLocator::ClosureResult));
2074
2065
if (resolvedTy)
2075
2066
return resolvedTy;
2076
2067
}
@@ -2354,9 +2345,7 @@ namespace {
2354
2345
2355
2346
const Type castType = resolveTypeReferenceInExpression (
2356
2347
isPattern->getCastTypeRepr (), TypeResolverContext::InExpression,
2357
- OpenUnboundGenericType (CS,
2358
- locator.withPathElement (
2359
- LocatorPathElt::PatternMatch (pattern))));
2348
+ locator.withPathElement (LocatorPathElt::PatternMatch (pattern)));
2360
2349
if (!castType) return Type ();
2361
2350
2362
2351
auto *subPattern = isPattern->getSubPattern ();
@@ -2407,32 +2396,31 @@ namespace {
2407
2396
FunctionRefKind functionRefKind = FunctionRefKind::Compound;
2408
2397
if (enumPattern->getParentType () || enumPattern->getParentTypeRepr ()) {
2409
2398
// Resolve the parent type.
2410
- Type parentType = [&]() -> Type {
2411
- if (auto preTy = enumPattern->getParentType ()) {
2412
- return preTy;
2399
+ const auto parentType = [&] {
2400
+ auto *const patternMatchLoc = CS.getConstraintLocator (
2401
+ locator, {LocatorPathElt::PatternMatch (pattern),
2402
+ ConstraintLocator::ParentType});
2403
+
2404
+ // FIXME: Sometimes the parent type is realized eagerly in
2405
+ // ResolvePattern::visitUnresolvedDotExpr, so we have to open it
2406
+ // ex post facto. Remove this once we learn how to resolve patterns
2407
+ // while generating constraints to keep the opening of generic types
2408
+ // contained within the type resolver.
2409
+ if (const auto preresolvedTy = enumPattern->getParentType ()) {
2410
+ const auto openedTy =
2411
+ CS.openUnboundGenericTypes (preresolvedTy, patternMatchLoc);
2412
+ assert (openedTy);
2413
+ return openedTy;
2413
2414
}
2415
+
2414
2416
return resolveTypeReferenceInExpression (
2415
2417
enumPattern->getParentTypeRepr (),
2416
- TypeResolverContext::InExpression, [](auto unboundTy) {
2417
- // FIXME: We ought to pass an OpenUnboundGenericType object
2418
- // rather than calling CS.openUnboundGenericType below, but
2419
- // sometimes the parent type is resolved eagerly in
2420
- // ResolvePattern::visitUnresolvedDotExpr, letting unbound
2421
- // generics escape.
2422
- return unboundTy;
2423
- });
2418
+ TypeResolverContext::InExpression, patternMatchLoc);
2424
2419
}();
2425
2420
2426
2421
if (!parentType)
2427
2422
return Type ();
2428
2423
2429
- parentType = CS.openUnboundGenericTypes (
2430
- parentType, CS.getConstraintLocator (
2431
- locator, {LocatorPathElt::PatternMatch (pattern),
2432
- ConstraintLocator::ParentType}));
2433
-
2434
- assert (parentType);
2435
-
2436
2424
// Perform member lookup into the parent's metatype.
2437
2425
Type parentMetaType = MetatypeType::get (parentType);
2438
2426
CS.addValueMemberConstraint (
@@ -2976,8 +2964,7 @@ namespace {
2976
2964
// Validate the resulting type.
2977
2965
const auto toType = resolveTypeReferenceInExpression (
2978
2966
repr, TypeResolverContext::ExplicitCastExpr,
2979
- // Introduce type variables for unbound generics.
2980
- OpenUnboundGenericType (CS, CS.getConstraintLocator (expr)));
2967
+ CS.getConstraintLocator (expr));
2981
2968
if (!toType)
2982
2969
return nullptr ;
2983
2970
@@ -3003,8 +2990,7 @@ namespace {
3003
2990
auto *const repr = expr->getCastTypeRepr ();
3004
2991
const auto toType = resolveTypeReferenceInExpression (
3005
2992
repr, TypeResolverContext::ExplicitCastExpr,
3006
- // Introduce type variables for unbound generics.
3007
- OpenUnboundGenericType (CS, CS.getConstraintLocator (expr)));
2993
+ CS.getConstraintLocator (expr));
3008
2994
if (!toType)
3009
2995
return nullptr ;
3010
2996
@@ -3036,8 +3022,7 @@ namespace {
3036
3022
auto *const repr = expr->getCastTypeRepr ();
3037
3023
const auto toType = resolveTypeReferenceInExpression (
3038
3024
repr, TypeResolverContext::ExplicitCastExpr,
3039
- // Introduce type variables for unbound generics.
3040
- OpenUnboundGenericType (CS, CS.getConstraintLocator (expr)));
3025
+ CS.getConstraintLocator (expr));
3041
3026
if (!toType)
3042
3027
return nullptr ;
3043
3028
@@ -3064,8 +3049,7 @@ namespace {
3064
3049
auto &ctx = CS.getASTContext ();
3065
3050
const auto toType = resolveTypeReferenceInExpression (
3066
3051
expr->getCastTypeRepr (), TypeResolverContext::ExplicitCastExpr,
3067
- // Introduce type variables for unbound generics.
3068
- OpenUnboundGenericType (CS, CS.getConstraintLocator (expr)));
3052
+ CS.getConstraintLocator (expr));
3069
3053
if (!toType)
3070
3054
return nullptr ;
3071
3055
@@ -3273,9 +3257,9 @@ namespace {
3273
3257
Type visitEditorPlaceholderExpr (EditorPlaceholderExpr *E) {
3274
3258
if (auto *placeholderRepr = E->getPlaceholderTypeRepr ()) {
3275
3259
// Just resolve the referenced type.
3276
- // FIXME: The type reference needs to be opened into context.
3277
3260
return resolveTypeReferenceInExpression (
3278
- placeholderRepr, TypeResolverContext::InExpression, nullptr );
3261
+ placeholderRepr, TypeResolverContext::InExpression,
3262
+ CS.getConstraintLocator (E));
3279
3263
}
3280
3264
3281
3265
auto locator = CS.getConstraintLocator (E);
@@ -3346,9 +3330,7 @@ namespace {
3346
3330
// If a root type was explicitly given, then resolve it now.
3347
3331
if (auto rootRepr = E->getRootType ()) {
3348
3332
const auto rootObjectTy = resolveTypeReferenceInExpression (
3349
- rootRepr, TypeResolverContext::InExpression,
3350
- // Introduce type variables for unbound generics.
3351
- OpenUnboundGenericType (CS, locator));
3333
+ rootRepr, TypeResolverContext::InExpression, locator);
3352
3334
if (!rootObjectTy || rootObjectTy->hasError ())
3353
3335
return Type ();
3354
3336
0 commit comments