Check and raise semantics errors on nested variables captures in patterns

This commit makes these codes to be invalid.

```ruby
case 0
in [a] | 1
end

case 0
in { a: b } | 1
end

case 0
in [{ a: [{ b: [{ c: }] }] }] | 1
end
```
This commit is contained in:
yui-knk 2025-11-26 14:11:23 +09:00 committed by Yuichiro Kaneko
parent a211abbcbd
commit dfdc5d40ec
Notes: git 2025-12-03 01:18:54 +00:00
2 changed files with 1 additions and 6 deletions

View File

@ -5468,11 +5468,6 @@ p_top_expr_body : p_expr
;
p_expr : p_as
{
p->ctxt.in_alt_pattern = 0;
p->ctxt.capture_in_pattern = 0;
$$ = $1;
}
;
p_as : p_expr tASSOC p_variable
@ -5494,6 +5489,7 @@ p_alt : p_alt[left] '|'[alt]
if (p->ctxt.capture_in_pattern) {
yyerror1(&@alt, "alternative pattern after variable capture");
}
p->ctxt.in_alt_pattern = 0;
$$ = NEW_OR($left, $right, &@$, &@alt);
/*% ripper: binary!($:left, ID2VAL(idOr), $:right) %*/
}

View File

@ -1 +0,0 @@
exclude(:test_alternative_pattern_nested, "Deeply nested captures variables are missing a syntax error")