-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Description
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