Fix cascading parse errors for parenthesized expressions at top level#9059
Draft
Fix cascading parse errors for parenthesized expressions at top level#9059
Conversation
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>
|
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 |
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
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.statement_unexpected_tokenerror pointing to the opening parenthesisFixes #9046
Co-authored by Claude Opus 4.5