From b9e225fcbfd045e65f1a95bcef16d97cbfb97287 Mon Sep 17 00:00:00 2001 From: tompng Date: Sat, 28 Sep 2024 13:15:29 +0900 Subject: [PATCH] Allow dot3 in defs singleton --- parse.y | 9 +++++++-- test/ruby/test_syntax.rb | 2 ++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/parse.y b/parse.y index a60ab68afe..16a687b594 100644 --- a/parse.y +++ b/parse.y @@ -3426,7 +3426,6 @@ defn_head : k_def def_name defs_head : k_def singleton dot_or_colon { SET_LEX_STATE(EXPR_FNAME); - p->ctxt.in_argdef = 1; } def_name { @@ -6746,8 +6745,14 @@ singleton : var_ref value_expr($1); $$ = $1; } - | '(' {SET_LEX_STATE(EXPR_BEG);} expr rparen + | '(' { + SET_LEX_STATE(EXPR_BEG); + p->ctxt.in_argdef = 0; + } + expr rparen + { + p->ctxt.in_argdef = 1; NODE *expr = last_expr_node($3); switch (nd_type(expr)) { case NODE_STR: diff --git a/test/ruby/test_syntax.rb b/test/ruby/test_syntax.rb index 5c341a69b7..3ea6932b9c 100644 --- a/test/ruby/test_syntax.rb +++ b/test/ruby/test_syntax.rb @@ -1968,6 +1968,8 @@ eom assert_valid_syntax("def foo b = 1, ...; bar(...); end") assert_valid_syntax("(def foo ...\n bar(...)\nend)") assert_valid_syntax("(def foo ...; bar(...); end)") + assert_valid_syntax("def (1...).foo ...; bar(...); end") + assert_valid_syntax("def (tap{1...}).foo ...; bar(...); end") assert_valid_syntax('def ==(...) end') assert_valid_syntax('def [](...) end') assert_valid_syntax('def nil(...) end')