Hey everybody
I was just trying to create a SetOnly
property wrapper that would allow for properties that have a setter without an available getter:
@propertyWrapper
struct SetOnly<Wrapped> {
private var value: Wrapped
var wrappedValue: Wrapped {
@available(*, unavailable) get { fatalError("This should be unreachable.") }
set { value = newValue }
}
init(wrappedValue: Wrapped) {
self.value = wrappedValue
}
}
struct S {
@SetOnly var t: Int
}
var s = S(t: 10)
s.t
I understand that set-only properties are a topic unto themselves, but that's not the point of this post.
It's rather about that fatal error placed in the wrappedValue
's getter saying "This should be unreachable."
. I thought that fatal error would be unreachable because the getter is marked as @available(*, unavailable)
. But accessing s.t
on the last line is not unavailable, and in fact the fatal error executes.
Is this intended behavior for property wrappers, or is this a bug?