Compiler can't infer types with Parameter Packs containing more than three elements

That's debatable. I also use parameter packs, but doing so is rather a world of pain.

Here are two:

typealias Itself<Value> = Value

extension Expanded {
  func addingExpansions<each New>(
    _ expansion: repeat each New
  ) -> Expanded<Base, repeat each Expansion, repeat each New> {
    .init(base: base, expansions: (repeat each self.expansions, repeat each expansion))
  }
}
var more = (
  ( initial
    .addingExpansion(Two())
    .addingExpansion(Three())
    as Itself
  )
  .addingExpansion(Four()) as Itself
)
  .addingExpansion(One())

var smore = initial.addingExpansions(
  Two(), Three(), Four(), One()
)

But keep in mind to expect that pain.

For example, this is all fine:

more = smore

let makeMore = {
  initial.addingExpansions(
    Two(), Three(), Four(), One()
  )
}

more = makeMore()

But any of this will yield the error

Cannot assign value of type 'Expanded<String, One, Two, Three, Four, One>' to type 'Expanded<String, One, Two, Three, Four, One>'

more = initial.addingExpansions(
  Two(), Three(), Four(), One()
)
more = {
  initial.addingExpansions(
    Two(), Three(), Four(), One()
  )
} ()

// Yes, this is exactly the copied and pasted code from above, aside from `var`.
smore = initial.addingExpansions(
  Two(), Three(), Four(), One()
)
1 Like