Skip to content

integer generic parameter not considered when conforming to protocol with static property requirement #84027

@lukaskollmer

Description

@lukaskollmer

Description

SE-0452 states that "Integer generic parameters of types become static members of that type, with the same visibility as the type itself".

While this is indeed the case, it seems that these static members are not taken into account when the type conforms to a protocol that requires a static member of type Int with the same name as that of the integer generic parameter.

It is possible to work around this, by explicitly declaring a static property with the same name as that of the integer generic parameter and simply returning that value from the property, but that then leads to another (likely incorrect?) compiler warning (see #84026)

Reproduction

protocol P {
    static var count: Int { get }
}

struct S<let count: Int>: P {}
// ^ error: type 'S<count>' does not conform to protocol 'P'
//          (protocol requires property 'count' with type 'Int')

Expected behavior

the compiler should treat the integer generic parameter as a proper static member of the type, and should allow it to satisfy the protocol requirement for a static Int property with the same name.

this should only be the case if the protocol requirement is for a get property; were the protocol to define static var count: Int { get set } instead, this would not work.

Environment

swift-driver version: 1.127.14.1 Apple Swift version 6.2 (swiftlang-6.2.0.19.9 clang-1700.3.19.1)
Target: arm64-apple-macosx15.0

(from Xcode 26 beta 6)

Additional information

see also #84026 as a possibly closely related issue

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