Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SR-14005] Omit any leading unlabeled function parameters with default cause "error: missing argument for parameter #n in call" #56398

Closed
mattyoung opened this issue Dec 30, 2020 · 2 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself

Comments

@mattyoung
Copy link

Previous ID SR-14005
Radar rdar://problem/72864712
Original Reporter @mattyoung
Type Bug
Status Resolved
Resolution Won't Do
Environment

macOS Big Sur 11.1
Xcode Version 12.3 (12C33) Xcode Playground

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug
Assignee None
Priority Medium

md5: c0c448b173e2622f5ea7a112ce7273a6

Issue Description:

All the function calls that omit leading parameter with default do not compile:

see: https://forums.swift.org/t/swiftui-withanimation-first-param-has-default-value-so-why-withanimation-doit-doesnt-compile/43442/2

func ƒ(_: Int = 0, _: Bool) { }
ƒ(false)    // error: missing argument for parameter #​1 in call

func ƒƒ(_: Int = 0, _: Int = 0, _: Bool) { }
ƒƒ(false)    // error: missing argument for parameter #​3 in call


struct Foo {
    static func (_: Int = 0, _: Bool) { }
    func ƒ(_: Int = 0, _: Bool) { }
}

Foo.(false)   // error: missing argument for parameter #​1 in call
let foo = Foo()
foo.ƒ(false)    // error: missing argument for parameter #​1 in call
@typesanitizer
Copy link

@swift-ci create

@typesanitizer
Copy link

I think this is intentional.

If you look at https://github.com/apple/swift-evolution/blob/master/proposals/0060-defaulted-parameter-order.md, it only mentions

Arbitrary labeled parameters with default arguments may still be elided

It doesn't say "arbitrary parameters", only "arbitrary labeled parameters".

There is also a forum thread discussing this issue here: https://forums.swift.org/t/ordering-of-unnamed-parameters-parameters-with-default-values/24153 . Here is the main part:

Type-checking occurs after arguments are matched to parameters.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself
Projects
None yet
Development

No branches or pull requests

2 participants