Description
Description
(First posted to the forums.)
Currently, a key path formed to a property that has an unavailable setter are WritableKeyPaths. This seems like a bug, since it allows code like dynamic member lookup to quietly compile what should crash at runtime.
While tracking the availability itself in the key path seems like a good idea and would allow library users to surface their own error messaging, I imagine that is a complex project to take on. Maybe as a baby step, key paths should at the very least be simply non-writable KeyPaths when the setter is unavailable.
Reproduction
struct S {
var p: String {
get { "" }
@available(*, unavailable)
set { fatalError() }
}
}
let kp: WritableKeyPath = \S.p
Expected behavior
The key path returned should be KeyPath
, not WritableKeyPath
, so the above should not compile.
Environment
swift-driver version: 1.90.11.1 Apple Swift version 5.10 (swiftlang-5.10.0.13 clang-1500.3.9.4)
Target: arm64-apple-macosx14.0
Additional information
No response