ruff
038235c6 - [parser] Fix false syntax error for match-like annotated assignments (#23297)

Commit
2 days ago
[parser] Fix false syntax error for match-like annotated assignments (#23297) ## Summary Fixes #22528. The parser incorrectly treats `match[0]: int` and `match [x, y, z]: {dict}` as the start of a `match` statement, producing a false syntax error. The issue is that the parser checks only for a colon after the subject expression to confirm a match statement, but annotated assignments with `match` as a variable name also have a colon. This PR adds a `self.peek() == TokenKind::Newline` guard to the colon check, so that `match` is only treated as a keyword when the colon is followed by a newline (which is required for a match statement's body). When the colon is followed by something else (like a type annotation value), it falls through to the soft-keyword-as-identifier path. ## Test Plan All 42 existing match-related parser tests pass. No snapshot changes needed. Clippy clean. Reproduction from the issue: ```python # These should parse without error: match[0]: int match [x, y, z]: {0: "a", 1: "b"} ```
Author
Parents
Loading