Skip to content

Commit c62b7ea

Browse files
committed
Add keypath write test for -swift-version 5.
1 parent fea720f commit c62b7ea

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

test/Constraints/keypath_swift_5.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,17 @@ struct S {
55

66
init() {
77
let _: WritableKeyPath<S, Int> = \.i // expected-error {{type of expression is ambiguous without more context}}
8+
9+
S()[keyPath: \.i] = 1
10+
// expected-error@-1 {{cannot assign to immutable expression}}
811
}
912
}
1013

1114
func test() {
1215
let _: WritableKeyPath<C, Int> = \.i // expected-error {{type of expression is ambiguous without more context}}
16+
17+
C()[keyPath: \.i] = 1
18+
// expected-error@-1 {{cannot assign to immutable expression}}
19+
20+
let _ = C()[keyPath: \.i] // no warning for a read
1321
}

0 commit comments

Comments
 (0)