@@ -2350,11 +2350,10 @@ namespace {
2350
2350
// / Build an implicit argument for keypath based dynamic lookup,
2351
2351
// / which consists of KeyPath expression and a single component.
2352
2352
// /
2353
- // / \param keyPathTy The type of the keypath argument.
2353
+ // / \param argType The type of the keypath subscript argument.
2354
2354
// / \param dotLoc The location of the '.' preceding member name.
2355
2355
// / \param memberLoc The locator to be associated with new argument.
2356
- Expr *buildKeyPathDynamicMemberArgExpr (BoundGenericType *keyPathTy,
2357
- SourceLoc dotLoc,
2356
+ Expr *buildKeyPathDynamicMemberArgExpr (Type argType, SourceLoc dotLoc,
2358
2357
ConstraintLocator *memberLoc) {
2359
2358
using Component = KeyPathExpr::Component;
2360
2359
auto &ctx = cs.getASTContext ();
@@ -2363,7 +2362,7 @@ namespace {
2363
2362
auto makeKeyPath = [&](ArrayRef<Component> components) -> Expr * {
2364
2363
auto *kp = KeyPathExpr::createImplicit (ctx, /* backslashLoc*/ dotLoc,
2365
2364
components, anchor->getEndLoc ());
2366
- kp->setType (keyPathTy );
2365
+ kp->setType (argType );
2367
2366
cs.cacheExprTypes (kp);
2368
2367
2369
2368
// See whether there's an equivalent ObjC key path string we can produce
@@ -2372,6 +2371,10 @@ namespace {
2372
2371
return kp;
2373
2372
};
2374
2373
2374
+ Type keyPathTy = argType;
2375
+ if (auto *existential = keyPathTy->getAs <ExistentialType>())
2376
+ keyPathTy = existential->getExistentialLayout ().explicitSuperclass ;
2377
+
2375
2378
SmallVector<Component, 2 > components;
2376
2379
auto *componentLoc = cs.getConstraintLocator (
2377
2380
memberLoc,
@@ -3482,8 +3485,8 @@ namespace {
3482
3485
auto fieldName = overload.choice .getName ().getBaseIdentifier ().str ();
3483
3486
argExpr = buildDynamicMemberLookupArgExpr (fieldName, nameLoc, paramTy);
3484
3487
} else {
3485
- argExpr = buildKeyPathDynamicMemberArgExpr (
3486
- paramTy-> castTo <BoundGenericType>() , dotLoc, memberLocator);
3488
+ argExpr =
3489
+ buildKeyPathDynamicMemberArgExpr (paramTy , dotLoc, memberLocator);
3487
3490
}
3488
3491
3489
3492
if (!argExpr)
0 commit comments