Skip to content

Prism rejects a trailing comma in a pattern-matching loop condition before do, while parse.y accepts it#4154

Open
kai-matsudate wants to merge 1 commit into
ruby:mainfrom
kai-matsudate:fix-pattern-loop-do-trailing-comma
Open

Prism rejects a trailing comma in a pattern-matching loop condition before do, while parse.y accepts it#4154
kai-matsudate wants to merge 1 commit into
ruby:mainfrom
kai-matsudate:fix-pattern-loop-do-trailing-comma

Conversation

@kai-matsudate

@kai-matsudate kai-matsudate commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Fixes Bug #22140.

Pattern matching syntax is parsed by parse_pattern. When a pattern has a trailing comma, Prism checks the token after the comma to decide whether the pattern ends there or another pattern should follow.

PM_TOKEN_KEYWORD_DO_LOOP was not included in that terminator set, so while a in b, do end were rejected even though parse.y accepts them. The same issue also applies to until and for loops.

This change treats PM_TOKEN_KEYWORD_DO_LOOP as a pattern terminator after a trailing comma, so the loop do delimiter is not parsed as the start of another pattern.

@kai-matsudate
kai-matsudate force-pushed the fix-pattern-loop-do-trailing-comma branch from 42356fd to f704a93 Compare July 16, 2026 23:44
Prism rejected pattern-matching loop conditions with a trailing comma before the `do` delimiter, while parse.y accepts them.

Treat `PM_TOKEN_KEYWORD_DO_LOOP` as a terminator after a trailing comma, so the loop `do` delimiter is not parsed as another pattern.
@kai-matsudate
kai-matsudate force-pushed the fix-pattern-loop-do-trailing-comma branch from f704a93 to 94b778c Compare July 17, 2026 00:02
@kai-matsudate
kai-matsudate marked this pull request as ready for review July 17, 2026 00:13
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.

1 participant