Skip to content

Incorrect (but understandable) fix-it for missing labels on a function with non-final default arguments #72208

Open
@jrose-signal

Description

@jrose-signal

Description

The compiler has a very nice fix-it to add or correct labels for a function call that is unambiguous, yet has the wrong labels. However, this fix-it is incorrect when a non-final default argument gets involved.

Reproduction

func test(a: Bool, b: Int = 0, c: String) {
}

test(true, "")

This produces

missing argument labels 'a:b:' in call
test(true, "")
    ^
     a:    b: 
<source>:5:14: error: missing argument for parameter 'c' in call
test(true, "")
             ^
             , c: <#String#>
<source>:1:6: note: 'test(a:b:c:)' declared here
func test(a: Bool, b: Int = 0, c: String) {
     ^
<source>:5:12: error: cannot convert value of type 'String' to expected argument type 'Int'
test(true, "")
           ^

Expected behavior

missing argument labels 'a:c:' in call
with a fix-it, and no further diagnostics.

Environment

Godbolt's swift-5.9-RELEASE

Additional information

I suspect the current behavior isn't looking at the argument types at all, but even with that it could still prefer a:c: by virtue of there being only two provided arguments. I realize that heuristic would break down pretty quickly with multiple defaults, but even so.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.call expressionsFeature → expressions: Call expressionscompilerThe Swift compiler itselfdefault argumentsFeature: default arguments for value parametersdiagnostics QoIBug: Diagnostics Quality of ImplementationexpressionsFeature: expressionsfix-itsFeature: diagnostic fix-itsswift 5.9type checkerArea → compiler: Semantic analysisunexpected behaviorBug: Unexpected behavior or incorrect output

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions