Can't figure out how to extend a result from variadic generics

I'm using the compiler that comes with Xcode 15.4.

@available(macOS 14.0.0, *) // Need to replace with "swift" version
public struct MyType<
  First: Collection,
  Second: Collection,
  Third: Collection,
  each Suffix: Collection
> {
    //...
}

@available(macOS 14.0.0, *) // Need to replace with "swift" version
extension MyType: IteratorProtocol {
  public func next() -> (First.Element, Second.Element, Third.Element, XXX)? {
    return nil
  }
}

What do I put at XXX?

  • each Suffix.Element gives "Pack reference 'Suffix.Element' requires expansion using keyword 'repeat'"
  • repeat each Suffix.Element gives "'each' cannot be applied to non-pack type '(each Suffix).Element'"
  • repeat Suffix.Element gives "Type pack 'Suffix.Element' must be referenced with 'each'"
  • repeat Suffix.each Element gives both "Expected ',' separator" and "Type pack 'Suffix.each' must be referenced with 'each'" Trying the suggested fixes crashes Xcode.
  • repeat each (Suffix).Element gives "'each' cannot be applied to non-pack type '(each Suffix).Element'"
  • repeat each (Suffix.Element) gives "'each' cannot be applied to non-pack type '(each Suffix).Element'"

I expect the most obvious one, the second, to work. The sixth is kind of acceptable, same for the fifth.

It is repeat (each Suffix).Element. I personally would like to see “sugar” rules for each so that this wouldn’t be necessary, but the base rule is that you can’t refer to the pack without each, and so you have to make sure those two are most tightly bound together.

2 Likes

Thanks.