Skip to content

Fix crashes / internal errors induced by parser error recovery#3539

Open
fangyi-zhou wants to merge 2 commits into
facebook:mainfrom
fangyi-zhou:fix-3343-empty-decorator-scope
Open

Fix crashes / internal errors induced by parser error recovery#3539
fangyi-zhou wants to merge 2 commits into
facebook:mainfrom
fangyi-zhou:fix-3343-empty-decorator-scope

Conversation

@fangyi-zhou
Copy link
Copy Markdown
Contributor

@fangyi-zhou fangyi-zhou commented May 22, 2026

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

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.
@github-actions
Copy link
Copy Markdown

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

@yangdanny97
Copy link
Copy Markdown
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.

@fangyi-zhou fangyi-zhou marked this pull request as ready for review May 22, 2026 09:24
@meta-codesync
Copy link
Copy Markdown
Contributor

meta-codesync Bot commented May 22, 2026

@yangdanny97 has imported this pull request. If you are a Meta employee, you can view this in D106082357.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

panic: Name '' not found in static scope of module __unknown__ with fuzzed code

2 participants