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

fix parser diagnostic regression when the error points to an empty span immediately after a line terminator #15510

Open
BurntSushi opened this issue Jan 15, 2025 · 0 comments
Labels
bug Something isn't working diagnostics Related to reporting of diagnostics.

Comments

@BurntSushi
Copy link
Member

While #15359 fixed a ton of bugs with our diagnostic rendering, it did introduce one regression related to parser diagnostics. Specifically, prior to #15359, we would get the following diagnostic in one case of a syntax error:

   |
12 | exept:  # spellchecker:disable-line
13 |     pass
14 | b = 1
   |  Syntax Error: Expected a statement
   |

(This is from crates/ruff_python_parser/tests/snapshots/invalid_syntax@try_stmt_misspelled_except.py.snap.)

Now, the ^ is missing from the above. After #15359, the caret is added, but the diagnostic is now pointing at the end of the preceding line:

   |
12 | exept:  # spellchecker:disable-line
13 |     pass
   |         ^ Syntax Error: Expected a statement
14 | b = 1
   |

We might be able to fix this by tweaking the ranges emitted by the parser when creating a diagnostic:

self.add_error(
recovery_context_kind.create_error(self),
self.current_token_range(),
);

But I think it would probably be better to fix the renderer itself so that it points to the beginning of the following line automatically.

See #15509 which is related to this issue. These issues are technically separate since this one could be fixed independently of #15509. But if #15509 is fixed, then I think this one will automatically resolve itself as well.

@BurntSushi BurntSushi added the bug Something isn't working label Jan 15, 2025
@MichaReiser MichaReiser added the diagnostics Related to reporting of diagnostics. label Jan 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working diagnostics Related to reporting of diagnostics.
Projects
None yet
Development

No branches or pull requests

2 participants