swift icon indicating copy to clipboard operation
swift copied to clipboard

[SR-2242] QoI: poor diagnostic when argument label is omitted

Open rudkx opened this issue 10 years ago • 6 comments

Previous ID SR-2242
Radar rdar://problem/27212391
Original Reporter @rudkx
Type Bug
Status Closed
Resolution Done

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

md5: 5fc39c2b102d27d0dd480337f34cfad1

Issue Description:

We currently emit:

  error: unnamed argument #​2 must precede unnamed argument #​1

for the following, which isn't reasonable, because the real issue here is that argument label x: is missing. If you actually swap the arguments you get the exact same error.

func unnamed(x: Int, _ y: Int) -> Int {
  return x + y
}

func test() -> Int {
  return unnamed(3, 5)
}

rudkx avatar Aug 01 '16 18:08 rudkx

@rintaro, you've recently been working on improvements here. Is this something you'd be willing to look at soon?

If not feel free to assign back to me.

rudkx avatar Aug 01 '16 19:08 rudkx

@rudkx I'm aware of this bug. The test case was already in the repo: 612991e.
before I started working around here.

I guess there is something wrong in constraints::matchCallArguments in lib/Sema/CSSimplify.cpp.
But, unfortunately, I don't have time to look into this right now. 🙁

rintaro avatar Aug 02 '16 06:08 rintaro

I think this may be related:

func foo(x: Int, _ y: Int) -> Int { return x + y }

_ = foo(1, y: 2)

results in:

order.swift:3:12: error: argument 'y' must precede unnamed argument #​1
_ = foo(1, y: 2)
        ~  ^~~~
        y: 2 1

rudkx avatar Sep 21 '16 22:09 rudkx

Yeah, that's the exact same issue.

I took a brief look yesterday and indeed, matchCallArguments is the culprit here.

Basically, when the first argument doesn't match, it moves on to the second, which steals the first unmatched parameter, so in the final cleanup it thinks they're out of order.

Might be nice to rework this by starting with a simple handful of test cases with desired behavior.

jtbandes avatar Sep 21 '16 23:09 jtbandes

Yeah, I assumed it was the same issue but since I haven't looked too closely at the code didn't want to state it as a fact.

rudkx avatar Sep 22 '16 00:09 rudkx