Skip to content

Commit 1a1e770

Browse files
committed
Test / Sema: Change the wording of assignment through read-only key path error
1 parent cefbb12 commit 1a1e770

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

lib/Sema/CSDiagnostics.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -989,16 +989,16 @@ bool AssignmentFailure::diagnoseAsError() {
989989
if (!choice->isDecl()) {
990990
if (choice->getKind() == OverloadChoiceKind::KeyPathApplication &&
991991
!isa<ApplyExpr>(immInfo.first)) {
992-
std::string message = "the key path";
992+
std::string message = "";
993993
if (auto *SE = dyn_cast<SubscriptExpr>(immInfo.first)) {
994994
if (auto *tupleExpr = dyn_cast<TupleExpr>(SE->getIndex())) {
995995
if (auto *DRE = dyn_cast<DeclRefExpr>(tupleExpr->getElement(0))) {
996996
auto identifier = DRE->getDecl()->getBaseName().getIdentifier();
997-
message = "'" + identifier.str().str() + "'";
997+
message = "'" + identifier.str().str() + "' ";
998998
}
999999
}
10001000
}
1001-
emitDiagnostic(Loc, DeclDiagnostic, message + " is a read-only key path")
1001+
emitDiagnostic(Loc, DeclDiagnostic, message + "is read-only")
10021002
.highlight(immInfo.first->getSourceRange());
10031003
return true;
10041004
}
@@ -1016,7 +1016,7 @@ bool AssignmentFailure::diagnoseAsError() {
10161016
auto type = getType(immInfo.first);
10171017

10181018
if (isKnownKeyPathType(type))
1019-
message += " is a read-only key path";
1019+
message += " is read-only";
10201020
else if (VD->isCaptureList())
10211021
message += " is an immutable capture";
10221022
else if (VD->isImplicit())

test/Constraints/keypath_swift_5.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ struct S {
77
let _: WritableKeyPath<S, Int> = \.i // expected-error {{cannot convert value of type 'KeyPath<S, Int>' to specified type 'WritableKeyPath<S, Int>'}}
88

99
S()[keyPath: \.i] = 1
10-
// expected-error@-1 {{cannot assign through subscript: the key path is a read-only key path}}
10+
// expected-error@-1 {{cannot assign through subscript: is read-only}}
1111
}
1212
}
1313

1414
func test() {
1515
let _: WritableKeyPath<C, Int> = \.i // expected-error {{cannot convert value of type 'KeyPath<C, Int>' to specified type 'WritableKeyPath<C, Int>'}}
1616

1717
C()[keyPath: \.i] = 1
18-
// expected-error@-1 {{cannot assign through subscript: the key path is a read-only key path}}
18+
// expected-error@-1 {{cannot assign through subscript: is read-only}}
1919

2020
let _ = C()[keyPath: \.i] // no warning for a read
2121
}
@@ -31,6 +31,6 @@ struct T {
3131
func testReadOnlyKeyPathDiagnostics() {
3232
let path = \T.a
3333
var t = T(a: 3)
34-
t[keyPath: path] = 4 // expected-error {{cannot assign through subscript: 'path' is a read-only key path}}
35-
t[keyPath: \T.a] = 4 // expected-error {{cannot assign through subscript: the key path is a read-only key path}}
34+
t[keyPath: path] = 4 // expected-error {{cannot assign through subscript: 'path' is read-only}}
35+
t[keyPath: \T.a] = 4 // expected-error {{cannot assign through subscript: is read-only}}
3636
}

0 commit comments

Comments
 (0)