@@ -267,27 +267,6 @@ static bool buildObjCKeyPathString(KeyPathExpr *E,
267
267
return true ;
268
268
}
269
269
270
- // / Form a type checked expression for the index of a @dynamicMemberLookup
271
- // / subscript index parameter.
272
- // / The index expression will have a tuple type of `(dynamicMember: T)`.
273
- static Expr *buildDynamicMemberLookupIndexExpr (StringRef name, SourceLoc loc,
274
- DeclContext *dc,
275
- ConstraintSystem &cs) {
276
- auto &ctx = cs.getASTContext ();
277
-
278
- auto *stringDecl = ctx.getStringDecl ();
279
- auto stringType = stringDecl->getDeclaredType ();
280
-
281
- // Build and type check the string literal index value to the specific
282
- // string type expected by the subscript.
283
- auto *nameExpr = new (ctx) StringLiteralExpr (name, loc, /* implicit*/ true );
284
- nameExpr->setBuiltinInitializer (ctx.getStringBuiltinInitDecl (stringDecl));
285
- nameExpr->setType (stringType);
286
-
287
- cs.cacheExprTypes (nameExpr);
288
- return nameExpr;
289
- }
290
-
291
270
namespace {
292
271
293
272
// / Rewrites an expression by applying the solution of a constraint
@@ -2717,6 +2696,18 @@ namespace {
2717
2696
llvm_unreachable (" Unhandled OverloadChoiceKind in switch." );
2718
2697
}
2719
2698
2699
+ // / Form a type checked expression for the index of a @dynamicMemberLookup
2700
+ // / subscript index parameter.
2701
+ Expr *buildDynamicMemberLookupIndexExpr (StringRef name, SourceLoc loc,
2702
+ Type literalTy) {
2703
+ // Build and type check the string literal index value to the specific
2704
+ // string type expected by the subscript.
2705
+ auto &ctx = cs.getASTContext ();
2706
+ auto *nameExpr = new (ctx) StringLiteralExpr (name, loc, /* implicit*/ true );
2707
+ cs.setType (nameExpr, literalTy);
2708
+ return handleStringLiteralExpr (nameExpr);
2709
+ }
2710
+
2720
2711
Expr *buildDynamicMemberLookupRef (Expr *expr, Expr *base, SourceLoc dotLoc,
2721
2712
SourceLoc nameLoc,
2722
2713
const SelectedOverload &overload,
@@ -2737,7 +2728,8 @@ namespace {
2737
2728
// Build and type check the string literal index value to the specific
2738
2729
// string type expected by the subscript.
2739
2730
auto fieldName = overload.choice .getName ().getBaseIdentifier ().str ();
2740
- argExpr = buildDynamicMemberLookupIndexExpr (fieldName, nameLoc, dc, cs);
2731
+ argExpr = buildDynamicMemberLookupIndexExpr (fieldName, nameLoc,
2732
+ paramTy);
2741
2733
} else {
2742
2734
argExpr = buildKeyPathDynamicMemberIndexExpr (
2743
2735
paramTy->castTo <BoundGenericType>(), dotLoc, memberLocator);
@@ -4529,16 +4521,8 @@ namespace {
4529
4521
auto subscript = cast<SubscriptDecl>(overload.choice .getDecl ());
4530
4522
assert (!subscript->isGetterMutating ());
4531
4523
4532
- auto dc = subscript->getInnermostDeclContext ();
4533
-
4534
- auto indexType = AnyFunctionType::composeInput (
4535
- cs.getASTContext (),
4536
- subscript->getInterfaceType ()->castTo <AnyFunctionType>()->getParams (),
4537
- /* canonicalVararg=*/ false );
4538
-
4539
4524
// Compute substitutions to refer to the member.
4540
4525
auto ref = resolveConcreteDeclRef (subscript, locator);
4541
- indexType = indexType.subst (ref.getSubstitutions ());
4542
4526
4543
4527
// If this is a @dynamicMemberLookup reference to resolve a property
4544
4528
// through the subscript(dynamicMember:) member, restore the
@@ -4556,15 +4540,15 @@ namespace {
4556
4540
4557
4541
labels = cs.getASTContext ().Id_dynamicMember ;
4558
4542
4543
+ auto indexType = getTypeOfDynamicMemberIndex (overload);
4559
4544
if (overload.choice .getKind () ==
4560
4545
OverloadChoiceKind::KeyPathDynamicMemberLookup) {
4561
- auto indexType = getTypeOfDynamicMemberIndex (overload);
4562
4546
indexExpr = buildKeyPathDynamicMemberIndexExpr (
4563
4547
indexType->castTo <BoundGenericType>(), componentLoc, locator);
4564
4548
} else {
4565
4549
auto fieldName = overload.choice .getName ().getBaseIdentifier ().str ();
4566
4550
indexExpr = buildDynamicMemberLookupIndexExpr (fieldName, componentLoc,
4567
- dc, cs );
4551
+ indexType );
4568
4552
}
4569
4553
}
4570
4554
0 commit comments