Pitch #2: Extend Property Wrappers to Function and Closure Parameters

Ok, I see the difference now, but is that a feature? I'm not sure that allowing different initializer when calling into the same function leads to a consistent design. At least, I don't think it's congruent with any other Swift's function calling resolution*. It feels like an unintentional side effect, more so that there's no motivational example.

* I got curious and checked this on member-wise initializer, which is the only function with property wrapper in the argument.

The initializer seems to always be choosing the generic one.
protocol P { }

@propertyWrapper
struct Wrapper<Value> {
    var wrappedValue: Value
    let projectedValue: String
    
    init(wrappedValue: Value) {
        projectedValue = "Generic"
        self.wrappedValue = wrappedValue
    }
}

extension Wrapper where Value: P {
    init(wrappedValue: Value) {
        projectedValue = "P"
        self.wrappedValue = wrappedValue
    }
}

struct X<Value> {
    @Wrapper var x: Value
}

extension Int: P { }

X(x: 1).$x // Generic
X(x: "T").$x // Generic
1 Like