The attached small program involving a generic struct S with a type parameter pack and an extension S<Bool, Int> { ... } should not compile, but it compiles without errors and runs, as if the extension had been extension S { ... }.
Reproduction
% swiftc --version
swift-driver version: 1.87.3 Apple Swift version 5.9.2 (swiftlang-5.9.2.2.56 clang-1500.1.0.2.5)
Target: x86_64-apple-macosx14.0
% cat > test.swift
struct S<each T> {
typealias Storage = (repeat each T)
let elements: (repeat each T)
init(_ element: repeat each T) {
self.elements = (repeat each element)
}
}
extension S<Bool, Int> {
func foo() { print("Hmm:", type(of: self), "...") }
}
func testS() {
let e = UInt8(123)
let s = S(e, e, e)
print(type(of: s))
s.foo() // Works, even though S<UInt8, UInt8, UInt8> != S<Bool, Int>
}
testS()
^C
Description
The attached small program involving a generic struct
S
with a type parameter pack and anextension S<Bool, Int> { ... }
should not compile, but it compiles without errors and runs, as if the extension had beenextension S { ... }
.Reproduction
Expected behavior
Should result in a compile time error.
Environment
Additional information
https://forums.swift.org/t/extensions-and-variadic-generic-types/68955