Skip to content

Commit cefbb12

Browse files
committed
Test: Update swift 5 keypath tests to reflect and test new behavior
1 parent 1d22e98 commit cefbb12

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

test/Constraints/keypath_swift_5.swift

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,30 @@ 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: immutable key path}}
10+
// expected-error@-1 {{cannot assign through subscript: the key path is a read-only key path}}
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: immutable key path}}
18+
// expected-error@-1 {{cannot assign through subscript: the key path is a read-only key path}}
1919

2020
let _ = C()[keyPath: \.i] // no warning for a read
2121
}
22+
23+
24+
struct T {
25+
private(set) var a: Int
26+
init(a: Int) {
27+
self.a = a
28+
}
29+
}
30+
31+
func testReadOnlyKeyPathDiagnostics() {
32+
let path = \T.a
33+
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}}
36+
}

0 commit comments

Comments
 (0)