[SR-2242] QoI: poor diagnostic when argument label is omitted
| 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)
}
@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 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. 🙁
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
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.
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.
A fix was merged into master: https://github.com/apple/swift/commit/366a3a0cd1576e8b1b6ba5d0edf2199e66f534a2