Skip to content

[SR-494] Cannot call function with variadic arguments before a required unnamed parameter #43111

Closed
@lilyball

Description

@lilyball
mannequin
Previous ID SR-494
Radar None
Original Reporter @lilyball
Type Bug
Environment

Apple Swift version 2.1.1 (swiftlang-700.1.101.15 clang-700.1.81)
Apple Swift version 2.2-dev (LLVM 3ebdbb2c7e, Clang f66c5bb67b, Swift 54dcd16)

Additional Detail from JIRA
Votes 1
Component/s Compiler
Labels Bug, TypeChecker
Assignee None
Priority Medium

md5: 9c3271fc49314ea7082f4bfb393d4cff

relates to:

  • SR-2475 QoI: Warn about unlabeled parameters following a variadic parameter

Issue Description:

When declaring a function that takes variadic arguments followed by a required parameter, such as

func foo(xs: Int..., _ y: String) { print(xs, y) }

this is accepted, but there's no way to call the function. Any attempt to do so fails with an error, e.g.

foo(1, 2, "three")

fails with the error

error: missing argument for parameter #2 in call

I consider this a bug, because this call is unambiguous. There is a single required parameter after the variadic arguments, which means that the last parameter in the call must correspond with this unnamed parameter.

More generally, Swift should be able to figure out how to invoke functions that have one or more unnamed parameters after the variadic parameter list as long as the unnamed parameters do not have default values.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselftype checkerArea → compiler: Semantic analysis

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions