swiftlang / swift

The Swift Programming Language
https://swift.org
Apache License 2.0
67.18k stars 10.32k forks source link

Compiler crash with trailing closure involving variadic types #67766

Open xAlien95 opened 1 year ago

xAlien95 commented 1 year ago

Description The following code is causing a compiler crash, with the error message Assertion failed: (origPackType.matchesPack(substPackType)), function PackElementGenerator, file AbstractionPattern.cpp, line 804 (Full output/stack dump).

if #available(macOS 14.0.0, *) {
  struct Tuple<each Element> {
    let element: (repeat each Element)

    init(_ element: repeat each Element) {
      self.element = (repeat each element)
    }
  }

  struct Wrapper<each Element> {
    let content: Tuple<repeat each Element>

    init(_ content: () -> Tuple<repeat each Element>) {
      self.content = content()
    }
  }

  _ = Wrapper { Tuple(1, 2) }
}

Steps to reproduce Build the script with the latest Swift development snapshot.

Expected behavior The compiler shouldn't crash.

Environment

Additional context The script compiles if you use an intermediate closure variable:

let closure = { Tuple(1, 2) }
_ = Wrapper(closure)
AnthonyLatsis commented 1 month ago

Reduction:

struct Foo<each T> {}

func takeClosure<each T>(_: () -> Foo<repeat each T>) {}

let _ = takeClosure({ Foo<Int, Int>() })