Skip to content

cannot define property-wrapper-based property with omitted type, if the property wrapper isn't directly initialized #81560

Open
@lukaskollmer

Description

@lukaskollmer

Description

The program below fails to compile, with the compiler complaining that the property-wrapper-backed property is missing an explicity type annotation.

Reproduction

@propertyWrapper
struct Query<T> {
    init(_ type: T.Type = T.self, limit: Int?) {}
    var wrappedValue: [T] { [] }
}


struct Item {}

struct S {
    @Query<Item> var items // error: type annotation missing in pattern
}

Expected behavior

IMO, this should compile, since there is no ambiguity w.r.t. the resulting wrappedValue type.

this would be different if the property were defined as @Query var items instead of @Query<Item> var items, since in that case the init call would be required to provide the type for T.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.triage neededThis issue needs more specific labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions