mirror of
https://github.com/ruby/ruby.git
synced 2026-01-26 20:19:19 +00:00
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:
parent
a211abbcbd
commit
dfdc5d40ec
Notes:
git
2025-12-03 01:18:54 +00:00
6
parse.y
6
parse.y
@ -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) %*/
|
||||
}
|
||||
|
||||
@ -1 +0,0 @@
|
||||
exclude(:test_alternative_pattern_nested, "Deeply nested captures variables are missing a syntax error")
|
||||
Loading…
x
Reference in New Issue
Block a user