Skip to content

extension S<Bool, Int> compiles as extension S for struct S<each T> #70432

Closed
@jepers

Description

@jepers

Description

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
% swiftc test.swift && ./test
S<Pack{UInt8, UInt8, UInt8}>
Hmm: S<Pack{UInt8, UInt8, UInt8}> ...

Expected behavior

Should result in a compile time error.

Environment

% 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

Additional information

https://forums.swift.org/t/extensions-and-variadic-generic-types/68955

Metadata

Metadata

Assignees

Labels

accepts invalidBug: Accepts invalidbugA deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselfdeclarationsFeature: declarationsextensionFeature → declarations: `extension` declarationsgenericsFeature: generic declarations and typesparameter packsFeature → generics: Parameter packsswift 6.0type checkerArea → compiler: Semantic analysis

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions