@@ -1408,13 +1408,12 @@ namespace {
1408
1408
// Compute the concrete reference to the subscript.
1409
1409
auto subscriptRef = resolveConcreteDeclRef (subscript, memberLoc);
1410
1410
1411
- // Figure out the index and result types.
1412
- auto subscriptTy = simplifyType (selected.openedType );
1413
- auto *subscriptFnTy = subscriptTy->castTo <FunctionType>();
1414
- auto resultTy = subscriptFnTy->getResult ();
1415
-
1416
1411
// Coerce the index argument.
1417
- index = coerceCallArguments (index, subscriptFnTy, subscriptRef, nullptr ,
1412
+ auto openedFullFnType = simplifyType (selected.openedFullType )
1413
+ ->castTo <FunctionType>();
1414
+ auto fullSubscriptTy = openedFullFnType->getResult ()
1415
+ ->castTo <FunctionType>();
1416
+ index = coerceCallArguments (index, fullSubscriptTy, subscriptRef, nullptr ,
1418
1417
argLabels, hasTrailingClosure,
1419
1418
locator.withPathElement (
1420
1419
ConstraintLocator::ApplyArgument));
@@ -1436,14 +1435,18 @@ namespace {
1436
1435
// TODO: diagnose if semantics != AccessSemantics::Ordinary?
1437
1436
auto subscriptExpr = DynamicSubscriptExpr::create (
1438
1437
ctx, base, index, subscriptRef, isImplicit, getType);
1438
+ auto resultTy = simplifyType (selected.openedType )
1439
+ ->castTo <FunctionType>()
1440
+ ->getResult ();
1441
+ assert (!selected.openedFullType ->hasOpenedExistential ()
1442
+ && " open existential archetype in AnyObject subscript type?" );
1439
1443
cs.setType (subscriptExpr, resultTy);
1440
1444
Expr *result = subscriptExpr;
1441
1445
closeExistential (result, locator);
1442
1446
return result;
1443
1447
}
1444
1448
1445
1449
// Convert the base.
1446
- auto openedFullFnType = selected.openedFullType ->castTo <FunctionType>();
1447
1450
auto openedBaseType =
1448
1451
getBaseType (openedFullFnType, /* wantsRValue*/ false );
1449
1452
auto containerTy = solution.simplifyType (openedBaseType);
@@ -1469,7 +1472,7 @@ namespace {
1469
1472
// Form the subscript expression.
1470
1473
auto subscriptExpr = SubscriptExpr::create (
1471
1474
ctx, base, index, subscriptRef, isImplicit, semantics, getType);
1472
- cs.setType (subscriptExpr, resultTy );
1475
+ cs.setType (subscriptExpr, fullSubscriptTy-> getResult () );
1473
1476
subscriptExpr->setIsSuper (isSuper);
1474
1477
1475
1478
Expr *result = subscriptExpr;
0 commit comments