Skip to content
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

Merged
merged 1 commit into from Feb 21, 2022

Conversation

adampauls
Copy link
Contributor

@adampauls adampauls commented Feb 15, 2022

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 the errorTermTree 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, in foo(5, :), previously, the errorTermTree 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 the errorTermTree.

@@ -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
Copy link
Contributor Author

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.

@adampauls
Copy link
Contributor Author

cc @som-snytt

@@ -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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another confusing error gone.

@adampauls adampauls changed the title Expand position on errorTermTree to include skipped span. Expand span errorTermTree to include skipped span. Feb 15, 2022
Copy link
Contributor

@odersky odersky left a 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?

@adampauls
Copy link
Contributor Author

adampauls commented Feb 21, 2022

Friendly ping @nicolasstucki , I think I am waiting on you to review. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants