Include span of bad args if multiline#25699
Conversation
01209e4 to
a5c5232
Compare
86ef31e to
c663284
Compare
| if pt.args.isEmpty then tree.srcPos | ||
| else | ||
| val union = tree.sourcePos.withSpan: | ||
| tree.srcPos.span.union(pt.args.last.srcPos.span) |
There was a problem hiding this comment.
What if tree.sourcePos is remapped (e.g. code has a magic header), while the union uses raw srcPos spans? Could that shift reported locations?
There was a problem hiding this comment.
I'll look at how that is done. On Scala 2, the "underlying" position was a function of the source. Otherwise, how could one do any position calculation? However, I endorse my comment about using API to request more context instead of touching position.
There was a problem hiding this comment.
Previously, shifting for funky headers was positionInUltimateSource, which may still be used in two places.
sourcePos.withSpan is the same as tree.source.atSpan or
val union = tree.sourcePos.copy(span = tree.srcPos.span.union(pt.args.last.srcPos.span))
Here we don't have a Positioned, we just want a SrcPos for reporting. Normally, reporting creates a Diagnostic and its SourcePosition together.
I won't push it further here, but it would be nice if reporting had a channel for extra pos info like inlined outers (currently a field in SourcePosition but really belongs to the diagnostic) and for this kludge a pos to say "rendering context should include this line".
There was a problem hiding this comment.
Makes sense. To be sure I tested it, and it doesn't seem to affect the case I mentioned.
There was a problem hiding this comment.
I don't know what IDEs do with multiline squiggles, however. Also, one could not do this trick and also emit a rewrite suggestion.
c663284 to
374ac9b
Compare
|
Just a rebase and a random NPE. We ought not to normalize that. |
mbovel
left a comment
There was a problem hiding this comment.
This PR enhance error messages about extra parameters for multi-line method calls by also showing the extra arguments that are on separate lines in the error message.
For example, before we would show:
-- [E050] Type Error: tests/neg/19087.scala:13:22 ----------------------------------------------------------------------
13 | foo(state.copy(x = 5): // Missing ")" // error: method copy in class State does not take more parameters
| ^^^^^^^^^^^^^^^^^
| method copy in class State does not take more parameters
|
And after:
-- [E050] Type Error: tests/neg/19087.scala:13:22 ----------------------------------------------------------------------
13 | foo(state.copy(x = 5): // Missing ")" // error: method copy in class State does not take more parameters
| ^
| method copy in class State does not take more parameters
|
14 | println("a")
|
Note the new line 14 | println("a").
It looks good to me!
Fixes #9434
The message position is tweaked only when the args are on a different line.
Then the source context includes the args; but only one caret for the point.
It would be nicer to request more context without changing the diagnostic position.