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
SI-8667 Improve too-many-args message #5147
Conversation
This is an improvement but Compare,
|
I think "expected" isn't the right word, because of defaults and tupling.
|
That formulation looks good. |
I'll miss the colloquial terseness of "too many args", and why did it even spell out "arguments", but thanks for the nudge. |
I didn't squash, in case someone prefers this terser version:
|
cad4392
to
1bdc217
Compare
I squashed with an update for gradual messages that depend on the arg count. Off by one for a short param list is different from off by 5 for a 22-arity generated function. Also made the "not a param name" message the same as for missing args. |
Here's the current Javac version for comparison's sake:
|
An alternative (or additional ) idea: should be focus the error message at the first superfluous argument, rather than at the invoked method. |
I'd forgotten that missing-args was fiddled with a year ago: #4586 |
Note to self, despite ambiguity of assignment, call out the erroneous
|
looks good to me - @janekdb @retronym can you take a look if you also like the new messages? https://github.com/scala/scala/pull/5147/files#diff-159fe691bd78013ef009e40722925f13 |
@@ -1,4 +1,4 @@ | |||
protected-constructors.scala:17: error: too many arguments for constructor Foo1: ()dingus.Foo1 | |||
protected-constructors.scala:17: error: no arguments allowed for nullary constructor Foo1: ()dingus.Foo1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
Exceeds my expectations so have a √LGTM leaving the deciding vote to @retronym. |
I haven't pushed retronym's idea to push the caret to the bad arg. |
Use removeNames to help diagnose the application. Supplement the error message with how many extra args and any other residual assignments that the user might have thought was a properly named arg. The error message is gradual: succinct for short arg lists, more verbose for longer applications. Very long arg lists are probably generated, so that message is the least colloquial.
1bdc217
to
9cfb406
Compare
Rebased. Moves the caret across the goal line. Also noted illustrious history https://issues.scala-lang.org/browse/SI-3818 |
Pick the first excessive positional arg for the caret. Note that erroring on named args doesn't do the obvious thing in this regard. If `k` was removed from the signature, then `f(k=1, i=2, j=3)` doesn't tell us much about the wrong arg, because naming takes the `k=1` as an assignment, `i` as duplicate naming. No arg is deemed extra, though further inspection of the conflicting args might get there. Since assignment syntax in parens is more|less deprecated (?), no more effort is done here.
9cfb406
to
40b42ae
Compare
protected-constructors.scala:15: error: no arguments allowed for nullary constructor Object: ()Object | ||
class Bar3 extends Ding.Foo3("abc") | ||
^ | ||
5 errors found |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the fifth error?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did it start showing up because the position changed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, in fact under -Ydebug
it was:
test/files/neg/protected-constructors.scala:15: error: [ suppressed ] too many arguments for primary constructor Object: ()lang.this.Object
class Bar3 extends Ding.Foo3("abc")
^
@retronym I moved the caret and a suppressed meaningless error is emitted. Is that a deal breaker? I didn't see a quick way to detect "I'd be suppressed at this other position." Lo and behold, a decoupled interface with Reporter is actually inconvenient if I can't interrogate it. Or add API, |
The Reporter API is certainly open to evolution (to simplify the process, we could start with an internal subtype that has richer methods than the API used by sbt etc). |
Positions can be shifted, as in scripts that begin at an offset into the source file. Analogously, you'd like to say, |
LGTM |
I'll follow up in future about the spurious error. I didn't see where the inaccessible super ctor results in using nullary ctor. You'd hope the error wouldn't cascade. But I also like that last idea, where an error position (for display) has an underlying unshifted position (for semantics). |
You could model something like that with the current API by issuing another error at the old position with a special message (e.g. empty string) that we could take as meaning it shouldn't be displayed. |
Use removeNames to help diagnose the application.
Supplement the error message with how many extra
args and any other residual assignments that the
user might have thought was a properly named arg.