Skip to content

[Bug #22310] Check only the left operand for captures in alternative patterns - #18830

Open
yuki-300 wants to merge 1 commit into
ruby:masterfrom
yuki-300:fix/alt-pattern-capture-check
Open

yuki-300 wants to merge 1 commit into
ruby:masterfrom
yuki-300:fix/alt-pattern-capture-check

Conversation

@yuki-300

@yuki-300 yuki-300 commented Sep 14, 2026 •

Copy link
Copy Markdown
Contributor

[Bug #22310]

capture_in_pattern is set by any binding in the whole in clause, so parse.y rejected in [ x, :a | :b ] while accepting in [ :a | :b, x ]. Keep the flag as a pre-check and walk the left operand for an actual binding, like Prism does. in_alt_pattern is now saved and restored around the right operand so a nested alternation does not clear it.

Regression from 4.0 (#15329), so this should be a backport candidate for 4.0.

@github-actions

Copy link
Copy Markdown

This pull request references the following Redmine tickets:

…patterns

`capture_in_pattern` is set by any binding in the whole `in` clause, so
`in [ x, :a | :b ]` was rejected while `in [ :a | :b, x ]` was accepted.
Keep the flag as a pre-check and walk the left operand for an actual
binding before raising, like Prism does. Save and restore
`in_alt_pattern` around the right operand so that a nested alternation
does not clear it.
@yuki-300
yuki-300 force-pushed the fix/alt-pattern-capture-check branch from ec84b61 to db30a13 Compare September 28, 2026 18:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

jit YJIT, ZJIT, ...

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant