@@ -1809,7 +1809,6 @@ namespace {
1809
1809
result = adjustTypeForDeclReference (result, resultTySelf,
1810
1810
resultType (adjustedRefTySelf),
1811
1811
locator);
1812
- closeExistentials (result, locator);
1813
1812
1814
1813
// If the property is of dynamic 'Self' type, wrap an implicit
1815
1814
// conversion around the resulting expression, with the destination
@@ -1821,6 +1820,8 @@ namespace {
1821
1820
result, resultTy));
1822
1821
}
1823
1822
1823
+ closeExistentials (result, locator);
1824
+
1824
1825
// If we need to load, do so now.
1825
1826
if (loadImmediately) {
1826
1827
result = cs.addImplicitLoadExpr (result);
@@ -2509,8 +2510,27 @@ namespace {
2509
2510
// Coerce the index argument.
2510
2511
auto openedFullFnType = simplifyType (selected.adjustedOpenedFullType )
2511
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
+
2512
2529
auto fullSubscriptTy = openedFullFnType->getResult ()
2513
2530
->castTo <FunctionType>();
2531
+ auto fullSubscriptTySelf = openedFullFnTypeSelf->getResult ()
2532
+ ->castTo <FunctionType>();
2533
+
2514
2534
auto appliedWrappers =
2515
2535
solution.getAppliedPropertyWrappers (memberLoc->getAnchor ());
2516
2536
args = coerceCallArguments (
@@ -2564,38 +2584,28 @@ namespace {
2564
2584
if (!base)
2565
2585
return nullptr ;
2566
2586
2567
- bool hasDynamicSelf = fullSubscriptTy->hasDynamicSelfType ();
2568
-
2569
2587
// Form the subscript expression.
2570
2588
auto subscriptExpr = SubscriptExpr::create (
2571
2589
ctx, base, args, subscriptRef, isImplicit, semantics);
2572
2590
subscriptExpr->setIsSuper (isSuper);
2573
2591
2574
- if (!hasDynamicSelf) {
2575
- cs.setType (subscriptExpr, fullSubscriptTy->getResult ());
2576
- } else {
2577
- cs.setType (subscriptExpr,
2578
- fullSubscriptTy->getResult ()
2579
- ->replaceDynamicSelfType (containerTy));
2580
- }
2592
+ cs.setType (subscriptExpr, fullSubscriptTySelf->getResult ());
2581
2593
2582
2594
Expr *result = subscriptExpr;
2583
- closeExistentials (result, locator);
2584
2595
2585
2596
// If the element is of dynamic 'Self' type, wrap an implicit conversion
2586
2597
// around the resulting expression, with the destination type having
2587
2598
// 'Self' swapped for the appropriate replacement type -- usually the
2588
2599
// base object type.
2589
- if (hasDynamicSelf) {
2590
- const auto conversionTy = simplifyType (
2591
- selected.adjustedOpenedType ->castTo <FunctionType>()->getResult ());
2592
-
2593
- if (!containerTy->isEqual (conversionTy)) {
2594
- result = cs.cacheType (
2595
- new (ctx) CovariantReturnConversionExpr (result, conversionTy));
2596
- }
2600
+ if (!fullSubscriptTy->getResult ()->isEqual (
2601
+ fullSubscriptTySelf->getResult ())) {
2602
+ result = cs.cacheType (
2603
+ new (ctx) CovariantReturnConversionExpr (
2604
+ result, fullSubscriptTy->getResult ()));
2597
2605
}
2598
2606
2607
+ closeExistentials (result, locator);
2608
+
2599
2609
return result;
2600
2610
}
2601
2611
0 commit comments