summaryrefslogtreecommitdiff
path: root/parse.y
diff options
context:
space:
mode:
authoryui-knk <spiketeika@gmail.com>2025-11-26 14:11:23 +0900
committerYuichiro Kaneko <spiketeika@gmail.com>2025-12-03 09:18:22 +0800
commitdfdc5d40ec25e42ff63982958c43d425bee909fb (patch)
treec20a29fe32cbebb70f886ad9c4dc5db83598b06f /parse.y
parenta211abbcbd87f6d59a99cfcf2cb63a39d61b16ea (diff)
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 ```
Diffstat (limited to 'parse.y')
-rw-r--r--parse.y6
1 files changed, 1 insertions, 5 deletions
diff --git a/parse.y b/parse.y
index f6222ea52e..a9fccdd5f7 100644
--- a/parse.y
+++ b/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) %*/
}