Fix crashes / internal errors induced by parser error recovery#3539
Open
fangyi-zhou wants to merge 2 commits into
Open
Fix crashes / internal errors induced by parser error recovery#3539fangyi-zhou wants to merge 2 commits into
fangyi-zhou wants to merge 2 commits into
Conversation
Ruff can recover from malformed decorator syntax by producing an annotated assignment whose target name is empty. Binding that synthesized identifier as a real definition violates the static-scope invariant and panics before Pyrefly can report the parse error. Skip definition binding for synthesized empty annotated-assignment targets while still checking the annotation and value when present. This preserves downstream diagnostics for recoverable syntax errors without inventing a real name.
Parser recovery can synthesize empty identifiers in match patterns. Those identifiers are parse artifacts, not real bindings, and trying to bind them can violate the static-scope invariant before parse diagnostics are reported. Skip synthesized empty match aliases and star/rest captures while preserving the normal pattern binding flow for valid names. The regression tests cover the match forms that panic without this filtering.
|
According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅ |
Contributor
|
That sandbox behavior sounds kind of bad lol. We should allow the text input to be edited and update local storage independently of the WASM bits, that way after a crash the user can fix their code and reload or something. |
Contributor
|
@yangdanny97 has imported this pull request. If you are a Meta employee, you can view this in D106082357. |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Fixes #3343
The fix is similar to 4980ddf / D104345441, just need to apply it to a few more places.
Asked GPT 5.5 to find a few other places where issues may occur and fix them as well, hopefully we're good.
P.S. I was testing the pre-patch behaviour using the web sandbox. It turns out that if the sandbox crashes, the text input is cached in local storage and makes the web sandbox unuseable without clearing local storage!
Test Plan
New regression tests added