I'm trying to create a property wrapper with a few a few different initializers depending on generics, but it seems that generic constraints break delayed initialization.
@propertyWrapper
struct PW<A, B> {
var wrappedValue: A
init(wrappedValue: A) where A == B {
self.wrappedValue = wrappedValue
}
}
struct X {
@PW var x: Int // 🛑 Generic parameter 'B' could not be inferred
}
If I remove the B
generic from PW
entirely, or if I eagerly assign a value:
struct X {
@PW var x = 1 // PW<Int, Int>
}
The inference works just fine.
Property wrapper initialization is certainly nuanced, so I might be missing what part of the feature prevents this from working, but should it work?