Skip to content

"Extra arguments" error when passing a parameter pack into a function that also accepts a closure argument. #70056

@simanerush

Description

@simanerush

Description

When trying to use a function that accepts a parameter pack and a closure as its arguments, I'm getting the "extra arguments" error.

Reproduction

func test<each T>(_ pack: repeat each T, callback: (repeat each T) -> Void) {}

test(1, 2, 3, callback: { _ in })

The error:

error: extra arguments at positions #2, #3 in call
test(1, 2, 3, callback: { _ in })
    ^
note: 'test(_:callback:)' declared here
func test<each T>(_ pack: repeat each T, callback: (repeat each T) -> Void) {
     ^

Expected behavior

The above code should compile because 1, 2, 3 is a valid parameter pack, and should be used as a first argument to the function.

Environment

Swift version 5.11-dev (LLVM d50917983d84235, Swift 98e65d0)

Additional information

The following code, with (repeat each T) replaced with (Int) in the type of the closure, works fine:

func test<each T>(_ pack: repeat each T, callback: (Int) -> Void) {}

test(1, 2, 3, callback: { _ in })

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.call expressionsFeature → expressions: Call expressionsclosuresFeature: closurescompilerThe Swift compiler itselfexpressionsFeature: expressionsgenericsFeature: generic declarations and typesnot a bugResolution → not a bug: Reported as a bug but turned out to be expected behavior or programmer errorparameter packsFeature → generics: Parameter packsswift 6.0type 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