From dfdc5d40ec25e42ff63982958c43d425bee909fb Mon Sep 17 00:00:00 2001 From: yui-knk Date: Wed, 26 Nov 2025 14:11:23 +0900 Subject: [PATCH] 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 ``` --- parse.y | 6 +----- test/.excludes-parsey/TestPatternMatching.rb | 1 - 2 files changed, 1 insertion(+), 6 deletions(-) delete mode 100644 test/.excludes-parsey/TestPatternMatching.rb 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) %*/ } diff --git a/test/.excludes-parsey/TestPatternMatching.rb b/test/.excludes-parsey/TestPatternMatching.rb deleted file mode 100644 index 20a1868d0c..0000000000 --- a/test/.excludes-parsey/TestPatternMatching.rb +++ /dev/null @@ -1 +0,0 @@ -exclude(:test_alternative_pattern_nested, "Deeply nested captures variables are missing a syntax error")