Skip to content

Fix parser panic on malformed tuple literals#62

Open
Wilfred wants to merge 1 commit intomainfrom
claude/fix-tuple-parser-bug-7HAJr
Open

Fix parser panic on malformed tuple literals#62
Wilfred wants to merge 1 commit intomainfrom
claude/fix-tuple-parser-bug-7HAJr

Conversation

@Wilfred
Copy link
Copy Markdown
Owner

@Wilfred Wilfred commented Apr 5, 2026

Summary

Fixed a parser panic that occurred when parsing malformed tuple literals where the parser failed to make forward progress after recovering from an invalid element.

Changes

  • Parser recovery logic: Changed the assertion in parse_tuple_literal_or_parentheses to a conditional check that breaks the parsing loop when parse_expression fails to consume any tokens, preventing infinite loops during error recovery
  • Test case: Added tuple_no_progress.gdn test file to verify the parser correctly handles malformed input like (,{ and emits appropriate diagnostics without panicking
  • Documentation: Updated CHANGELOG.md to document the fix

Implementation Details

The issue occurred because when parse_expression encountered an error and couldn't consume any tokens, the parser would remain at the same position and attempt to parse the next tuple element infinitely. The fix detects this condition and breaks out of the loop, allowing the parser to continue gracefully with error recovery already handled by the diagnostic system.

https://claude.ai/code/session_01Smbrb7sx8HkXRUkSXNLfme

When parse_expression failed to consume any tokens during tuple
element collection (e.g. for input `(,{`), the forward-progress
assertion aborted the parser. Break out of the loop instead so
the diagnostic is reported normally.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants