@@ -1239,6 +1239,14 @@ bool RValueTreatedAsLValueFailure::diagnoseAsError() {
1239
1239
if (auto callExpr = dyn_cast<ApplyExpr>(diagExpr)) {
1240
1240
Expr *argExpr = callExpr->getArg ();
1241
1241
loc = callExpr->getFn ()->getLoc ();
1242
+ auto *locator = getLocator ();
1243
+
1244
+ // `argument attribute` is used for identification purposes
1245
+ // only, so it could be looked through in this situation.
1246
+ if (locator->isLastElement <LocatorPathElt::ArgumentAttribute>()) {
1247
+ auto path = locator->getPath ();
1248
+ locator = getConstraintLocator (getRawAnchor (), path.drop_back ());
1249
+ }
1242
1250
1243
1251
if (isa<PrefixUnaryExpr>(callExpr) || isa<PostfixUnaryExpr>(callExpr)) {
1244
1252
subElementDiagID = diag::cannot_apply_lvalue_unop_to_subelement;
@@ -1247,16 +1255,14 @@ bool RValueTreatedAsLValueFailure::diagnoseAsError() {
1247
1255
} else if (isa<BinaryExpr>(callExpr)) {
1248
1256
subElementDiagID = diag::cannot_apply_lvalue_binop_to_subelement;
1249
1257
rvalueDiagID = diag::cannot_apply_lvalue_binop_to_rvalue;
1250
- auto argTuple = dyn_cast<TupleExpr>(argExpr);
1251
- diagExpr = argTuple->getElement (0 );
1252
- } else if (getLocator ()->getPath ().size () > 0 ) {
1253
- auto argElt =
1254
- getLocator ()->castLastElementTo <LocatorPathElt::ApplyArgToParam>();
1255
-
1258
+ diagExpr = castToExpr (simplifyLocatorToAnchor (locator));
1259
+ } else if (auto argElt =
1260
+ locator
1261
+ ->getLastElementAs <LocatorPathElt::ApplyArgToParam>()) {
1256
1262
subElementDiagID = diag::cannot_pass_rvalue_inout_subelement;
1257
1263
rvalueDiagID = diag::cannot_pass_rvalue_inout;
1258
1264
if (auto argTuple = dyn_cast<TupleExpr>(argExpr))
1259
- diagExpr = argTuple->getElement (argElt. getArgIdx ());
1265
+ diagExpr = argTuple->getElement (argElt-> getArgIdx ());
1260
1266
else if (auto parens = dyn_cast<ParenExpr>(argExpr))
1261
1267
diagExpr = parens->getSubExpr ();
1262
1268
} else {
0 commit comments