Skip to content

Commit e2d8824

Browse files
authored
Merge pull request #10001 from rudkx/fix-keypath-subscript-tests
Update tests of preferring subscript over keypath application.
2 parents fd693b4 + 0396271 commit e2d8824

File tree

1 file changed

+9
-14
lines changed

1 file changed

+9
-14
lines changed

test/expr/unary/keypath/keypath.swift

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -231,10 +231,10 @@ func testKeyPathSubscript(readonly: Z, writable: inout Z,
231231
}
232232

233233
struct ZwithSubscript {
234-
subscript(keyPath: KeyPath<ZwithSubscript, Int>) -> Int { return 0 }
235-
subscript(keyPath: WritableKeyPath<ZwithSubscript, Int>) -> Int { return 0 }
236-
subscript(keyPath: ReferenceWritableKeyPath<ZwithSubscript, Int>) -> Int { return 0 }
237-
subscript(keyPath: PartialKeyPath<ZwithSubscript>) -> Any { return 0 }
234+
subscript(keyPath kp: KeyPath<ZwithSubscript, Int>) -> Int { return 0 }
235+
subscript(keyPath kp: WritableKeyPath<ZwithSubscript, Int>) -> Int { return 0 }
236+
subscript(keyPath kp: ReferenceWritableKeyPath<ZwithSubscript, Int>) -> Int { return 0 }
237+
subscript(keyPath kp: PartialKeyPath<ZwithSubscript>) -> Any { return 0 }
238238
}
239239

240240
func testKeyPathSubscript(readonly: ZwithSubscript, writable: inout ZwithSubscript,
@@ -249,12 +249,9 @@ func testKeyPathSubscript(readonly: ZwithSubscript, writable: inout ZwithSubscri
249249
sink = readonly[keyPath: rkp]
250250
sink = writable[keyPath: rkp]
251251

252-
// FIXME: keypath application rather than subscripting if subscript parameter defined without a separate internal name
253-
readonly[keyPath: kp] = sink // expected-error{{cannot assign to immutable expression of type 'Int'}}
254-
// FIXME: keypath application rather than subscripting if subscript parameter defined without a separate internal name
255-
writable[keyPath: kp] = sink // expected-error{{cannot assign to immutable expression of type 'Int'}}
256-
// FIXME: keypath application rather than subscripting if subscript parameter defined without a separate internal name
257-
readonly[keyPath: wkp] = sink // expected-error{{cannot assign to immutable expression of type 'Int'}}
252+
readonly[keyPath: kp] = sink // expected-error{{cannot assign through subscript: subscript is get-only}}
253+
writable[keyPath: kp] = sink // expected-error{{cannot assign through subscript: subscript is get-only}}
254+
readonly[keyPath: wkp] = sink // expected-error{{cannot assign through subscript: subscript is get-only}}
258255
// FIXME: silently falls back to keypath application, which seems inconsistent
259256
writable[keyPath: wkp] = sink
260257
// FIXME: silently falls back to keypath application, which seems inconsistent
@@ -269,10 +266,8 @@ func testKeyPathSubscript(readonly: ZwithSubscript, writable: inout ZwithSubscri
269266
var anySink2 = writable[keyPath: pkp]
270267
expect(&anySink2, toHaveType: Exactly<Any>.self)
271268

272-
// FIXME: keypath application rather than subscripting if subscript parameter defined without a separate internal name
273-
readonly[keyPath: pkp] = anySink1 // expected-error{{cannot assign to immutable expression of type 'Any'}}
274-
// FIXME: keypath application rather than subscripting if subscript parameter defined without a separate internal name
275-
writable[keyPath: pkp] = anySink2 // expected-error{{cannot assign to immutable expression of type 'Any'}}
269+
readonly[keyPath: pkp] = anySink1 // expected-error{{cannot assign through subscript: subscript is get-only}}
270+
writable[keyPath: pkp] = anySink2 // expected-error{{cannot assign through subscript: subscript is get-only}}
276271

277272
let akp: AnyKeyPath = pkp
278273

0 commit comments

Comments
 (0)