diff options
| author | yui-knk <spiketeika@gmail.com> | 2023-08-31 21:35:55 +0900 |
|---|---|---|
| committer | Yuichiro Kaneko <spiketeika@gmail.com> | 2023-09-01 12:55:09 +0900 |
| commit | 45cd011d73ed1fac195d828c0565e2cac57f65fc (patch) | |
| tree | aad4c8611bc63e94a09682a79d4b4355a7e69f04 | |
| parent | df4c77608e76068deed58b2781674b0eb247c325 (diff) | |
[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.
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/8347
| -rw-r--r-- | parse.y | 9 | ||||
| -rw-r--r-- | test/ruby/test_syntax.rb | 15 |
2 files changed, 16 insertions, 8 deletions
@@ -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}')) |
