@@ -982,8 +982,8 @@ namespace {
982
982
// / Add constraints for a subscript operation.
983
983
Type addSubscriptConstraints (
984
984
Expr *anchor, Type baseTy, Expr *index,
985
- ValueDecl *declOrNull,
986
- ConstraintLocator *locator = nullptr ,
985
+ ValueDecl *declOrNull, ArrayRef<Identifier> argLabels,
986
+ bool hasTrailingClosure, ConstraintLocator *locator = nullptr ,
987
987
SmallVectorImpl<TypeVariableType *> *addedTypeVars = nullptr ) {
988
988
// Locators used in this expression.
989
989
if (locator == nullptr )
@@ -999,6 +999,8 @@ namespace {
999
999
CS.getConstraintLocator (locator,
1000
1000
ConstraintLocator::FunctionResult);
1001
1001
1002
+ associateArgumentLabels (memberLocator, {argLabels, hasTrailingClosure});
1003
+
1002
1004
Type outputTy;
1003
1005
1004
1006
// For an integer subscript expression on an array slice type, instead of
@@ -1229,8 +1231,9 @@ namespace {
1229
1231
}
1230
1232
1231
1233
Type visitObjectLiteralExpr (ObjectLiteralExpr *expr) {
1234
+ auto *exprLoc = CS.getConstraintLocator (expr);
1232
1235
associateArgumentLabels (
1233
- expr , {expr->getArgumentLabels (), expr->hasTrailingClosure ()});
1236
+ exprLoc , {expr->getArgumentLabels (), expr->hasTrailingClosure ()});
1234
1237
1235
1238
// If the expression has already been assigned a type; just use that type.
1236
1239
if (expr->getType ())
@@ -1244,13 +1247,13 @@ namespace {
1244
1247
return nullptr ;
1245
1248
}
1246
1249
1247
- auto tv = CS.createTypeVariable (CS. getConstraintLocator (expr) ,
1250
+ auto tv = CS.createTypeVariable (exprLoc ,
1248
1251
TVO_PrefersSubtypeBinding |
1249
1252
TVO_CanBindToNoEscape);
1250
1253
1251
1254
CS.addConstraint (ConstraintKind::LiteralConformsTo, tv,
1252
1255
protocol->getDeclaredType (),
1253
- CS. getConstraintLocator (expr) );
1256
+ exprLoc );
1254
1257
1255
1258
// The arguments are required to be argument-convertible to the
1256
1259
// idealized parameter type of the initializer, which generally
@@ -1511,7 +1514,8 @@ namespace {
1511
1514
CS.getConstraintLocator (expr, ConstraintLocator::ApplyFunction));
1512
1515
1513
1516
associateArgumentLabels (
1514
- expr, {expr->getArgumentLabels (), expr->hasTrailingClosure ()});
1517
+ CS.getConstraintLocator (expr),
1518
+ {expr->getArgumentLabels (), expr->hasTrailingClosure ()});
1515
1519
return baseTy;
1516
1520
}
1517
1521
@@ -1746,12 +1750,10 @@ namespace {
1746
1750
return Type ();
1747
1751
}
1748
1752
1749
- associateArgumentLabels (
1750
- expr, {expr->getArgumentLabels (), expr->hasTrailingClosure ()});
1751
-
1752
1753
return addSubscriptConstraints (expr, CS.getType (expr->getBase ()),
1753
1754
expr->getIndex (),
1754
- decl);
1755
+ decl, expr->getArgumentLabels (),
1756
+ expr->hasTrailingClosure ());
1755
1757
}
1756
1758
1757
1759
Type visitArrayExpr (ArrayExpr *expr) {
@@ -1995,10 +1997,10 @@ namespace {
1995
1997
}
1996
1998
1997
1999
Type visitDynamicSubscriptExpr (DynamicSubscriptExpr *expr) {
1998
- associateArgumentLabels (
1999
- expr, {expr->getArgumentLabels (), expr->hasTrailingClosure ()});
2000
2000
return addSubscriptConstraints (expr, CS.getType (expr->getBase ()),
2001
- expr->getIndex (), nullptr );
2001
+ expr->getIndex (), /* decl*/ nullptr ,
2002
+ expr->getArgumentLabels (),
2003
+ expr->hasTrailingClosure ());
2002
2004
}
2003
2005
2004
2006
Type visitTupleElementExpr (TupleElementExpr *expr) {
@@ -2488,7 +2490,8 @@ namespace {
2488
2490
2489
2491
SmallVector<Identifier, 4 > scratch;
2490
2492
associateArgumentLabels (
2491
- expr, {expr->getArgumentLabels (scratch), expr->hasTrailingClosure ()},
2493
+ CS.getConstraintLocator (expr),
2494
+ {expr->getArgumentLabels (scratch), expr->hasTrailingClosure ()},
2492
2495
/* labelsArePermanent=*/ isa<CallExpr>(expr));
2493
2496
2494
2497
if (auto *UDE = dyn_cast<UnresolvedDotExpr>(fnExpr)) {
@@ -3017,7 +3020,10 @@ namespace {
3017
3020
// re-type-check the constraints during failure diagnosis.
3018
3021
case KeyPathExpr::Component::Kind::Subscript: {
3019
3022
base = addSubscriptConstraints (E, base, component.getIndexExpr (),
3020
- /* decl*/ nullptr , memberLocator,
3023
+ /* decl*/ nullptr ,
3024
+ component.getSubscriptLabels (),
3025
+ /* hasTrailingClosure*/ false ,
3026
+ memberLocator,
3021
3027
&componentTypeVars);
3022
3028
break ;
3023
3029
}
@@ -3251,15 +3257,13 @@ namespace {
3251
3257
llvm_unreachable (" unhandled operation" );
3252
3258
}
3253
3259
3254
- void associateArgumentLabels (Expr *expr ,
3260
+ void associateArgumentLabels (ConstraintLocator *locator ,
3255
3261
ConstraintSystem::ArgumentInfo info,
3256
3262
bool labelsArePermanent = true ) {
3257
- assert (expr );
3263
+ assert (locator && locator-> getAnchor () );
3258
3264
// Record the labels.
3259
3265
if (!labelsArePermanent)
3260
3266
info.Labels = CS.allocateCopy (info.Labels );
3261
-
3262
- auto *locator = CS.getConstraintLocator (expr);
3263
3267
CS.ArgumentInfos [CS.getArgumentInfoLocator (locator)] = info;
3264
3268
}
3265
3269
};
0 commit comments