@@ -995,19 +995,20 @@ bool AssignmentFailure::diagnoseAsError() {
995
995
if (!choice->isDecl ()) {
996
996
if (choice->getKind () == OverloadChoiceKind::KeyPathApplication &&
997
997
!isa<ApplyExpr>(immInfo.first )) {
998
- std::string message = " " ;
998
+ std::string message = " key path is read-only " ;
999
999
if (auto *SE = dyn_cast<SubscriptExpr>(immInfo.first )) {
1000
1000
if (auto *DRE = dyn_cast<DeclRefExpr>(getKeyPathArgument (SE))) {
1001
1001
auto identifier = DRE->getDecl ()->getBaseName ().getIdentifier ();
1002
- message = " '" + identifier.str ().str () + " ' " ;
1002
+ message =
1003
+ " '" + identifier.str ().str () + " ' is a read-only key path" ;
1003
1004
}
1004
1005
}
1005
- emitDiagnostic (Loc, DeclDiagnostic, message + " is read-only " )
1006
+ emitDiagnostic (Loc, DeclDiagnostic, message)
1006
1007
.highlight (immInfo.first ->getSourceRange ());
1007
1008
return true ;
1008
1009
}
1009
1010
return false ;
1010
- }
1011
+ }
1011
1012
1012
1013
// Otherwise, we cannot resolve this because the available setter candidates
1013
1014
// are all mutating and the base must be mutating. If we dug out a
@@ -1042,7 +1043,7 @@ bool AssignmentFailure::diagnoseAsError() {
1042
1043
// note to fixit prepend a 'self.'.
1043
1044
if (auto typeContext = DC->getInnermostTypeContext ()) {
1044
1045
UnqualifiedLookup lookup (VD->getFullName (), typeContext,
1045
- getASTContext ().getLazyResolver ());
1046
+ getASTContext ().getLazyResolver ());
1046
1047
for (auto &result : lookup.Results ) {
1047
1048
const VarDecl *typeVar = dyn_cast<VarDecl>(result.getValueDecl ());
1048
1049
if (typeVar && typeVar != VD && typeVar->isSettable (DC) &&
@@ -1053,7 +1054,7 @@ bool AssignmentFailure::diagnoseAsError() {
1053
1054
dyn_cast_or_null<AccessorDecl>(DC->getInnermostMethodContext ());
1054
1055
if (!AD || AD->getStorage () != typeVar) {
1055
1056
emitDiagnostic (Loc, diag::masked_instance_variable,
1056
- typeContext->getSelfTypeInContext ())
1057
+ typeContext->getSelfTypeInContext ())
1057
1058
.fixItInsert (Loc, " self." );
1058
1059
}
1059
1060
}
@@ -1102,9 +1103,8 @@ bool AssignmentFailure::diagnoseAsError() {
1102
1103
.highlight (immInfo.first ->getSourceRange ());
1103
1104
return true ;
1104
1105
}
1105
-
1106
1106
}
1107
-
1107
+
1108
1108
// Fall back to producing diagnostics based on the expression since we
1109
1109
// couldn't determine anything from the OverloadChoice.
1110
1110
@@ -1265,7 +1265,7 @@ AssignmentFailure::resolveImmutableBase(Expr *expr) const {
1265
1265
auto *DC = getDC ();
1266
1266
expr = expr->getValueProvidingExpr ();
1267
1267
1268
- auto isImmutable = [&](ValueDecl *decl) {
1268
+ auto isImmutable = [&DC ](ValueDecl *decl) {
1269
1269
if (auto *storage = dyn_cast<AbstractStorageDecl>(decl))
1270
1270
return !storage->isSettable (nullptr ) ||
1271
1271
!storage->isSetterAccessibleFrom (DC);
@@ -1276,7 +1276,6 @@ AssignmentFailure::resolveImmutableBase(Expr *expr) const {
1276
1276
// Provide specific diagnostics for assignment to subscripts whose base expr
1277
1277
// is known to be an rvalue.
1278
1278
if (auto *SE = dyn_cast<SubscriptExpr>(expr)) {
1279
-
1280
1279
// If we found a decl for the subscript, check to see if it is a set-only
1281
1280
// subscript decl.
1282
1281
if (SE->hasDecl ()) {
@@ -1289,10 +1288,8 @@ AssignmentFailure::resolveImmutableBase(Expr *expr) const {
1289
1288
}
1290
1289
}
1291
1290
1292
- Optional<OverloadChoice> member;
1293
-
1294
- auto loc = cs.getConstraintLocator (SE, ConstraintLocator::SubscriptMember);
1295
- member = getMemberRef (loc);
1291
+ Optional<OverloadChoice> member = getMemberRef (
1292
+ cs.getConstraintLocator (SE, ConstraintLocator::SubscriptMember));
1296
1293
1297
1294
// If it isn't settable, return it.
1298
1295
if (member) {
@@ -1303,7 +1300,7 @@ AssignmentFailure::resolveImmutableBase(Expr *expr) const {
1303
1300
if (!member->isDecl ()) {
1304
1301
// This must be a keypath application
1305
1302
assert (member->getKind () == OverloadChoiceKind::KeyPathApplication);
1306
-
1303
+
1307
1304
auto *argType = getType (SE->getIndex ())->castTo <TupleType>();
1308
1305
assert (argType->getNumElements () == 1 );
1309
1306
0 commit comments