@@ -2510,8 +2510,27 @@ namespace {
2510
2510
// Coerce the index argument.
2511
2511
auto openedFullFnType = simplifyType (selected.adjustedOpenedFullType )
2512
2512
->castTo <FunctionType>();
2513
+
2514
+ auto openedFullFnTypeSelf = openedFullFnType;
2515
+
2516
+ // Now, deal with DynamicSelfType.
2517
+ if (selected.adjustedOpenedFullType ->hasDynamicSelfType ()) {
2518
+ openedFullFnTypeSelf = simplifyType (
2519
+ selected.adjustedOpenedFullType ->eraseDynamicSelfType ())
2520
+ ->castTo <FunctionType>();
2521
+ auto replacementTy = getDynamicSelfReplacementType (
2522
+ baseTy, subscript, memberLoc);
2523
+ openedFullFnType = simplifyType (
2524
+ selected.adjustedOpenedFullType
2525
+ ->replaceDynamicSelfType (replacementTy))
2526
+ ->castTo <FunctionType>();
2527
+ }
2528
+
2513
2529
auto fullSubscriptTy = openedFullFnType->getResult ()
2514
2530
->castTo <FunctionType>();
2531
+ auto fullSubscriptTySelf = openedFullFnTypeSelf->getResult ()
2532
+ ->castTo <FunctionType>();
2533
+
2515
2534
auto appliedWrappers =
2516
2535
solution.getAppliedPropertyWrappers (memberLoc->getAnchor ());
2517
2536
args = coerceCallArguments (
@@ -2565,38 +2584,28 @@ namespace {
2565
2584
if (!base)
2566
2585
return nullptr ;
2567
2586
2568
- bool hasDynamicSelf = fullSubscriptTy->hasDynamicSelfType ();
2569
-
2570
2587
// Form the subscript expression.
2571
2588
auto subscriptExpr = SubscriptExpr::create (
2572
2589
ctx, base, args, subscriptRef, isImplicit, semantics);
2573
2590
subscriptExpr->setIsSuper (isSuper);
2574
2591
2575
- if (!hasDynamicSelf) {
2576
- cs.setType (subscriptExpr, fullSubscriptTy->getResult ());
2577
- } else {
2578
- cs.setType (subscriptExpr,
2579
- fullSubscriptTy->getResult ()
2580
- ->replaceDynamicSelfType (containerTy));
2581
- }
2592
+ cs.setType (subscriptExpr, fullSubscriptTySelf->getResult ());
2582
2593
2583
2594
Expr *result = subscriptExpr;
2584
- closeExistentials (result, locator);
2585
2595
2586
2596
// If the element is of dynamic 'Self' type, wrap an implicit conversion
2587
2597
// around the resulting expression, with the destination type having
2588
2598
// 'Self' swapped for the appropriate replacement type -- usually the
2589
2599
// base object type.
2590
- if (hasDynamicSelf) {
2591
- const auto conversionTy = simplifyType (
2592
- selected.adjustedOpenedType ->castTo <FunctionType>()->getResult ());
2593
-
2594
- if (!containerTy->isEqual (conversionTy)) {
2595
- result = cs.cacheType (
2596
- new (ctx) CovariantReturnConversionExpr (result, conversionTy));
2597
- }
2600
+ if (!fullSubscriptTy->getResult ()->isEqual (
2601
+ fullSubscriptTySelf->getResult ())) {
2602
+ result = cs.cacheType (
2603
+ new (ctx) CovariantReturnConversionExpr (
2604
+ result, fullSubscriptTy->getResult ()));
2598
2605
}
2599
2606
2607
+ closeExistentials (result, locator);
2608
+
2600
2609
return result;
2601
2610
}
2602
2611
0 commit comments