-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Expand span errorTermTree to include skipped span. #14492
Conversation
@@ -10,7 +10,7 @@ object Test { | |||
val b = type // error: expression expected (on "type") | |||
|
|||
1 match { | |||
case // error: pattern expected // error: cannot compare with Null |
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.
This error leaks the implementation detail that parser errors produce a null.
cc @som-snytt |
ce65d3b
to
05d7dd5
Compare
@@ -21,9 +21,7 @@ class DiagnosticsTest { | |||
| Nil.map(x => x).filter(x$m1 =>$m2)$m3 | |||
|}""".withSource | |||
.diagnostics(m1, | |||
(m2 to m2, "expression expected but ')' found", Error, Some(IllegalStartSimpleExprID)), | |||
(m1 to m1, """Found: Null |
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.
Another confusing error gone.
05d7dd5
to
8e62f96
Compare
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.
Great improvement! Why did we not think of this before?
8e62f96
to
3bd8d31
Compare
3bd8d31
to
f0c9ff8
Compare
Friendly ping @nicolasstucki , I think I am waiting on you to review. Thanks! |
At present, when the parser encounters an error and produces
errorTermTree
, it first issues a syntax error, which has the side effect of skipping to the nearest "safe point" ()
, newline, etc.). This means that theerrorTermTree
conceptually covers the whole skipped span, but only the position right before the safe point token is included in the span of the error.This PR keeps track of the
lastOffset
before skipping tokens and includes everything from that offset up to the safe point in the span of the error. So for example, infoo(5, :)
, previously, theerrorTermTree
returned would not include the:
.This reduces the number of (redundant) errors, and in particular removes type-checking errors that arise from the presumably-private implementation detail of producing
Constant(null)
as theerrorTermTree
.