From 45cd011d73ed1fac195d828c0565e2cac57f65fc Mon Sep 17 00:00:00 2001 From: yui-knk Date: Thu, 31 Aug 2023 21:35:55 +0900 Subject: [PATCH] [Bug #19281] Allow semicolon in parenthesis at the first argument of command call Allow compstmt in the first argument of command call wrapped with parenthesis like following arguments with parenthesis. --- parse.y | 9 +-------- test/ruby/test_syntax.rb | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/parse.y b/parse.y index 1b103ca5fe..8b88b1b38d 100644 --- a/parse.y +++ b/parse.y @@ -3362,14 +3362,7 @@ primary : literal /*% %*/ /*% ripper: begin!($3) %*/ } - | tLPAREN_ARG {SET_LEX_STATE(EXPR_ENDARG);} rparen - { - /*%%%*/ - $$ = NEW_BEGIN(0, &@$); - /*% %*/ - /*% ripper: paren!(0) %*/ - } - | tLPAREN_ARG stmt {SET_LEX_STATE(EXPR_ENDARG);} rparen + | tLPAREN_ARG compstmt {SET_LEX_STATE(EXPR_ENDARG);} ')' { /*%%%*/ if (nd_type_p($2, NODE_SELF)) $2->nd_state = 0; diff --git a/test/ruby/test_syntax.rb b/test/ruby/test_syntax.rb index c65d7af4c2..cda84c6368 100644 --- a/test/ruby/test_syntax.rb +++ b/test/ruby/test_syntax.rb @@ -1650,6 +1650,21 @@ eom assert_valid_syntax('Foo::Bar() {}') end + def test_command_newline_in_tlparen_args + assert_valid_syntax("p (1\n2\n),(3),(4)") + assert_valid_syntax("p (\n),(),()") + assert_valid_syntax("a.b (1\n2\n),(3),(4)") + assert_valid_syntax("a.b (\n),(),()") + end + + def test_command_semicolon_in_tlparen_at_the_first_arg + bug19281 = '[ruby-core:111499] [Bug #19281]' + assert_valid_syntax('p (1;2),(3),(4)', bug19281) + assert_valid_syntax('p (;),(),()', bug19281) + assert_valid_syntax('a.b (1;2),(3),(4)', bug19281) + assert_valid_syntax('a.b (;),(),()', bug19281) + end + def test_numbered_parameter assert_valid_syntax('proc {_1}') assert_equal(3, eval('[1,2].then {_1+_2}'))