From 6279e45cdefa3e61ca1c9c8085b15727cb2f4a60 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Fri, 25 Oct 2019 00:06:43 +0900 Subject: [PATCH] Arguments forwarding is not allowed in lambda [Feature #16253] --- parse.y | 24 +++++++++++++----------- test/ruby/test_syntax.rb | 2 ++ 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/parse.y b/parse.y index 657e521982..c3e385e0af 100644 --- a/parse.y +++ b/parse.y @@ -4781,6 +4781,19 @@ f_arglist : '(' f_args rparen SET_LEX_STATE(EXPR_BEG); p->command_start = TRUE; } + | '(' args_forward rparen + { + arg_var(p, idFWD_REST); + arg_var(p, idFWD_KWREST); + arg_var(p, idFWD_BLOCK); + /*%%%*/ + $$ = new_args_tail(p, Qnone, idFWD_KWREST, idFWD_BLOCK, &@2); + $$ = new_args(p, Qnone, Qnone, idFWD_REST, Qnone, $$, &@2); + /*% %*/ + /*% ripper: paren!(params_new(Qnone, Qnone, $2, Qnone, Qnone, Qnone, Qnone)) %*/ + SET_LEX_STATE(EXPR_BEG); + p->command_start = TRUE; + } | { $$ = p->in_kwarg; p->in_kwarg = 1; @@ -4883,17 +4896,6 @@ f_args : f_arg ',' f_optarg ',' f_rest_arg opt_args_tail { $$ = new_args(p, Qnone, Qnone, Qnone, Qnone, $1, &@$); } - | args_forward - { - arg_var(p, idFWD_REST); - arg_var(p, idFWD_KWREST); - arg_var(p, idFWD_BLOCK); - /*%%%*/ - $$ = new_args_tail(p, Qnone, idFWD_KWREST, idFWD_BLOCK, &@1); - $$ = new_args(p, Qnone, Qnone, idFWD_REST, Qnone, $$, &@$); - /*% %*/ - /*% ripper: params_new(Qnone, Qnone, $1, Qnone, Qnone, Qnone, Qnone) %*/ - } | /* none */ { $$ = new_args_tail(p, Qnone, Qnone, Qnone, &@0); diff --git a/test/ruby/test_syntax.rb b/test/ruby/test_syntax.rb index 5b933d9682..5bbcbef3a4 100644 --- a/test/ruby/test_syntax.rb +++ b/test/ruby/test_syntax.rb @@ -1476,6 +1476,8 @@ eom assert_valid_syntax('def foo(...) end') assert_syntax_error('iter do |...| end', /unexpected/) assert_syntax_error('iter {|...|}', /unexpected/) + assert_syntax_error('->... {}', /unexpected/) + assert_syntax_error('->(...) {}', /unexpected/) assert_syntax_error('def foo(x, y, z) bar(...); end', /unexpected/) assert_syntax_error('def foo(x, y, z) super(...); end', /unexpected/) assert_syntax_error('def foo(...) yield(...); end', /unexpected/)