Skip to content

Fix cascading parse errors for parenthesized expressions at top level#9059

Draft
rtfeldman wants to merge 5 commits intomainfrom
fix-issue-9046
Draft

Fix cascading parse errors for parenthesized expressions at top level#9059
rtfeldman wants to merge 5 commits intomainfrom
fix-issue-9046

Conversation

@rtfeldman
Copy link
Contributor

Summary

When encountering a parenthesized expression like (x = 5).foo() at the top level of a module, the parser now produces a single parse error instead of cascading errors for each token.

  • Added logic to skip past the entire parenthesized expression and any suffix operators when at top level
  • Produces a single statement_unexpected_token error pointing to the opening parenthesis
  • Added snapshot test to verify the behavior

Fixes #9046

Co-authored by Claude Opus 4.5

rtfeldman and others added 5 commits January 21, 2026 00:30
When encountering a parenthesized expression like (x = 5).foo() at the
top level of a module, the parser now skips past the entire expression
and produces a single parse error instead of producing multiple
statement_unexpected_token errors for each token.

Previously, the parser would not consume any tokens when it detected
that a parenthesized construct at top level was not a destructuring
pattern, causing it to produce cascading errors for each token.

Fixes #9046

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
When skipping a parenthesized expression at top level, the lookahead loop
might hit EndOfFile before finding the matching close paren. In this case,
we should not try to advance past the EOF token as that would cause an
assertion failure in peek().

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
After skipping a parenthesized expression at top level, we need to back up
one position before calling pushMalformed because pushMalformed always
advances. This ensures the parser doesn't skip past the first token of
the next statement, which would cause cascading errors.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
The parser fix reduces cascading errors when encountering parenthesized
expressions at top level. This test now only has 2 parse errors instead
of 6, as the ( tokens are no longer processed individually but skipped
as a group.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
The parser fix reduces cascading errors when encountering parenthesized
expressions at top level. These snapshot tests now reflect the improved
behavior with fewer parse errors.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@github-actions
Copy link

Thank you for your contribution! Sometimes PRs end up staying open for a long time without activity, which can make the list of open PRs get long and time-consuming to review. To keep things manageable for reviewers, this bot automatically closes PRs that haven’t had activity in 60 days. This PR hasn’t had activity in 30 days, so it will be automatically closed if there is no more activity in the next 30 days. Keep in mind that PRs marked Closed are not deleted, so no matter what, the PR will still be right here in the repo. You can always access it and reopen it anytime you like!

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.

Formatter crashes on inline definition in parentheses

1 participant