File tree Expand file tree Collapse file tree 1 file changed +9
-5
lines changed Expand file tree Collapse file tree 1 file changed +9
-5
lines changed Original file line number Diff line number Diff line change @@ -986,16 +986,20 @@ bool AssignmentFailure::diagnoseAsError() {
986
986
// Attempt diagnostics based on the overload choice.
987
987
if (choice.hasValue ()) {
988
988
989
+ auto getKeyPathArgument = [](SubscriptExpr *expr) {
990
+ auto *TE = dyn_cast<TupleExpr>(expr->getIndex ());
991
+ assert (TE->getNumElements () == 1 );
992
+ return TE->getElement (0 );
993
+ };
994
+
989
995
if (!choice->isDecl ()) {
990
996
if (choice->getKind () == OverloadChoiceKind::KeyPathApplication &&
991
997
!isa<ApplyExpr>(immInfo.first )) {
992
998
std::string message = " " ;
993
999
if (auto *SE = dyn_cast<SubscriptExpr>(immInfo.first )) {
994
- if (auto *tupleExpr = dyn_cast<TupleExpr>(SE->getIndex ())) {
995
- if (auto *DRE = dyn_cast<DeclRefExpr>(tupleExpr->getElement (0 ))) {
996
- auto identifier = DRE->getDecl ()->getBaseName ().getIdentifier ();
997
- message = " '" + identifier.str ().str () + " ' " ;
998
- }
1000
+ if (auto *DRE = dyn_cast<DeclRefExpr>(getKeyPathArgument (SE))) {
1001
+ auto identifier = DRE->getDecl ()->getBaseName ().getIdentifier ();
1002
+ message = " '" + identifier.str ().str () + " ' " ;
999
1003
}
1000
1004
}
1001
1005
emitDiagnostic (Loc, DeclDiagnostic, message + " is read-only" )
You can’t perform that action at this time.
0 commit comments