diff --git a/parse.y b/parse.y index 6c0da9ce687c23..0244ffc09c85a9 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 5c341a69b70b06..3ea6932b9c83c2 100644 --- a/test/ruby/test_syntax.rb +++ b/test/ruby/test_syntax.rb @@ -1968,6 +1968,8 @@ def test_argument_forwarding 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')