`@available` in computed `wrappedValue`

Hey everybody :wave:t2:

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?

S is supposed to be equivalent to

struct S {
    var _t: SetOnly<Int>
    var t: Int { 
        get { _t.wrappedValue }
        set { _t.wrappedValue = newValue }
    }
    init(t: Int) {
        _t = SetOnly(wrappedValue: t)
    }
}

which doesn't compile because of unavailable

Looks like a bug to me

Terms of Service

Privacy Policy

Cookie Policy