swiftlang/swift-syntax

SE-0399: `repeat each (repeat each t)` parses as function call

Closed this issue · 2 comments

Issue Kind

Parse of Valid Source Produced Invalid Syntax Tree

Source Code

func variadic<each T>(element: repeat each T) {
  _ = repeat each (repeat each element)
}

Description

swift-syntax twin of swiftlang/swift#69003.

Tracked in Apple’s issue tracker as rdar://116573588

This is expected behavior, each ( is intentionally parsed as a function call, as it could be valid if you had a function named each. As I understand it, SE-0399 only changed the type-checking rules around pack expansions, not the parsing rules (if it had changed the parsing rules, it would have needed to call out the source compatibility impact of each ( no longer being a function call).

I don't believe this is likely to be an issue in practice, since a pack expansion of a literal tuple pack expansion should be redundant and should be replaceable by the underlying pack expansion.