-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Include span of bad args if multiline #25699
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| -- [E018] Syntax Error: tests/neg/i9434.scala:10:18 -------------------------------------------------------------------- | ||
| 10 | Vector(1) ++ // error | ||
| | ^ | ||
| | expression expected but [31munindent[0m found | ||
| | | ||
| | longer explanation available when compiling with `-explain` | ||
| -- [E050] Type Error: tests/neg/i9434.scala:4:14 ----------------------------------------------------------------------- | ||
| 4 | val bar = foo // error | ||
| | ^ | ||
| | value foo does not take parameters | ||
| | | ||
| 5 | (1, 1) | ||
| | | ||
| | longer explanation available when compiling with `-explain` | ||
| -- [E007] Type Mismatch Error: tests/neg/i9434.scala:6:3 --------------------------------------------------------------- | ||
| 6 | } // error | ||
| | ^ | ||
| | Found: Unit | ||
| | Required: (Int, Int) | ||
| | | ||
| | Maybe the enclosing block is missing a final expression after the definition of `bar`? | ||
| | | ||
| | longer explanation available when compiling with `-explain` | ||
| -- [E050] Type Error: tests/neg/i9434.scala:26:29 ---------------------------------------------------------------------- | ||
| 26 | def f[A](as: List[A]) = as headOption // error | ||
| | ^ | ||
| | method headOption in trait LinearSeqOps does not take parameters | ||
| | | ||
| 27 | 42 | ||
| | | ||
| | longer explanation available when compiling with `-explain` | ||
| -- [E050] Type Error: tests/neg/i9434.scala:30:29 ---------------------------------------------------------------------- | ||
| 30 | def f[A](as: List[A]) = as headOption // error | ||
| | ^ | ||
| | method headOption in trait LinearSeqOps does not take parameters | ||
| | | ||
| 31 | 42 | ||
| | | ||
| | longer explanation available when compiling with `-explain` | ||
| -- [E050] Type Error: tests/neg/i9434.scala:35:10 ---------------------------------------------------------------------- | ||
| 35 | def f = g // error | ||
| | ^ | ||
| | method g in object Y does not take parameters | ||
| | | ||
| 36 | (42) | ||
| | | ||
| | longer explanation available when compiling with `-explain` | ||
| -- [E129] Potential Issue Warning: tests/neg/i9434.scala:41:2 ---------------------------------------------------------- | ||
| 41 | (42) // warn | ||
| | ^^^^ | ||
| | A pure expression does nothing in statement position | ||
| | | ||
| | longer explanation available when compiling with `-explain` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| object Foo { | ||
| def bar1: (Int, Int) = { | ||
| val foo = 1.0 | ||
| val bar = foo // error | ||
| (1, 1) | ||
| } // error | ||
|
|
||
| def bar2: Vector[Int] = { | ||
| val foo = | ||
| Vector(1) ++ // error | ||
| Vector(2) ++ | ||
| Vector(3) | ||
| foo | ||
| } | ||
| } | ||
| /* Now the diagnostic is multiline, to show more context (the args), and only one caret for the point. | ||
| -- [E050] Type Error: i9434.scala:5:14 --------------------------------------------------------------------------------- | ||
| 5 | val bar = foo | ||
| | ^^^ | ||
| | value foo does not take parameters | ||
| | | ||
| | longer explanation available when compiling with `-explain` | ||
| */ | ||
|
|
||
| object X: | ||
| def f[A](as: List[A]) = as headOption // error | ||
| 42 | ||
|
|
||
| object X2: | ||
| def f[A](as: List[A]) = as headOption // error | ||
| 42 | ||
|
|
||
| object Y: | ||
| def g = 42 | ||
| def f = g // error | ||
| (42) | ||
|
|
||
| object Z: | ||
| def g = 42 | ||
| def f = g | ||
| (42) // warn |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 if
tree.sourcePosis remapped (e.g. code has a magic header), while the union uses rawsrcPosspans? Could that shift reported locations?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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Previously, shifting for funky headers was
positionInUltimateSource, which may still be used in two places.sourcePos.withSpanis the same astree.source.atSpanorHere we don't have a
Positioned, we just want aSrcPosfor reporting. Normally, reporting creates aDiagnosticand itsSourcePositiontogether.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
SourcePositionbut 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know what IDEs do with multiline squiggles, however. Also, one could not do this trick and also emit a rewrite suggestion.