Skip to content

Matching a parameter pack to a tuple of closures that utilizes it compiles, but is impossible to use. #75558

Open
@JessyCatterwaul

Description

@JessyCatterwaul

Reproduction

Both forms compile without issue:

func mapWithoutTuple<each Input, each Output>(
  _ input: (repeat each Input),
  _ transform: repeat (each Input) -> each Output
) -> (repeat each Output) {
  (repeat (each transform)(each input))
}

func mapWithTuple<each Input, each Output>(
  _ input: (repeat each Input),
  _ transform: (repeat (each Input) -> each Output) // The difference is only these outer parentheses.
) -> (repeat each Output) {
  (repeat (each transform)(each input))
}

The first form is usable.

#expect(
  // Explicit "\Int.self" is required here. Maybe a different bug?
  mapWithoutTuple(0, \Int.self) as Int == 0
)
#expect(
  mapWithoutTuple((0, 1), \.self, \.self) == (0, 1)
)

The second form is not:

_ = mapWithTuple(0, \Int.self)
_ = mapWithTuple((0, 1), (\.self, \.self))

This results in various errors.

Expected behavior

While splatting would be ideal, where parameters being tuples, or not, didn't matter, we should at least be able to write overloads that use either form. And if a form compiles, it should be usable.

Environment

swift-driver version: 1.112.3 Apple Swift version 6.0 (swiftlang-6.0.0.6.8 clang-1600.0.23.1)
Target: arm64-apple-macosx14.0

Additional Information

This is not a problem with only one parameter pack.

func forEach<each Input, Error>(
  _ input: (repeat each Input),
  _ body: (repeat (each Input) throws(Error) -> Void)
) throws(Error) {
  repeat try (each body)(each input)
}
var value = 0
func add(_ summand: Int) { value += summand }
forEach((1, 2), (add, add))
#expect(value == 3) // ✅

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselfexpressionsFeature: expressionsgenericsFeature: generic declarations and typesparameter packsFeature → generics: Parameter packsswift 6.0tuplesFeature: tuplestype checkerArea → compiler: Semantic analysistype inferenceFeature: type inferenceunexpected errorBug: Unexpected error

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions