Description
Description
The compiler rejects code that defines a property-wrapper-based property, where the property wrapper is not directly initialized as part of the declaration, and it's wrappedValue
has an opaque type.
Additionally, since the type is opaque, we can't even specify it manually, since the compiler then complains about the types not matching.
In the example below, the items1
property fails to compile, with the compiler complaining that the type is missing.
Additionally, we can't specify the property's resulting type, since adding : some Collection<Item>
, will alfo fail, with the compiler complaining that "property type 'some Collection' (type of 'S.items1') does not match 'wrappedValue' type 'some Collection' (type of 'Query.wrappedValue')".
Reproduction
@propertyWrapper
struct Query<T> {
private var results: [T] = []
init(_ type: T.Type = T.self, limit: Int?) {}
var wrappedValue: some Collection<T> {
results
}
}
struct Item {}
struct S {
@Query<Item> private var items // error: type annotation missing in pattern
}
Expected behavior
it should either be allowed not to specify an explicit type in this scenario, since the resuting wrappedValue
type can be unabmiguously deduced from the context (see also #81560 ), or it should be allowed to put an opaque type as the property's type (e.g., some Collection<Item>
, in this case), with the compiler treating it properly if it matches the wrappedValue
type.
Environment
swift-driver version: 1.120.5 Apple Swift version 6.1 (swiftlang-6.1.0.110.21 clang-1700.0.13.3)
Target: arm64-apple-macosx15.0
Additional information
No response