From d325d74174c3ffffa0d75e248897cbb1aae93407 Mon Sep 17 00:00:00 2001 From: nobu Date: Thu, 20 Sep 2018 01:43:35 +0000 Subject: [PATCH] parse.y: fix block passing with empty kwargs * parse.y (arg_blk_pass): preceeding arguments node may be NULL when an empty keyword argument hash splat is optimized away. [ruby-core:88890] [Bug #15087] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64786 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- parse.y | 1 + test/ruby/test_keyword.rb | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/parse.y b/parse.y index fb471803a5..3763dabf3a 100644 --- a/parse.y +++ b/parse.y @@ -9962,6 +9962,7 @@ static NODE * arg_blk_pass(NODE *node1, NODE *node2) { if (node2) { + if (!node1) return node2; node2->nd_head = node1; nd_set_first_lineno(node2, nd_first_lineno(node1)); nd_set_first_column(node2, nd_first_column(node1)); diff --git a/test/ruby/test_keyword.rb b/test/ruby/test_keyword.rb index 8bf5d71f8e..84a5cfec66 100644 --- a/test/ruby/test_keyword.rb +++ b/test/ruby/test_keyword.rb @@ -563,7 +563,8 @@ class TestKeywordArguments < Test::Unit::TestCase def test_dynamic_symbol_keyword bug10266 = '[ruby-dev:48564] [Bug #10266]' - assert_separately(['-', bug10266], <<-'end;') # do + assert_separately(['-', bug10266], "#{<<~"begin;"}\n#{<<~'end;'}") + begin; bug = ARGV.shift "hoge".to_sym assert_nothing_raised(bug) {eval("def a(hoge:); end")} @@ -746,4 +747,8 @@ class TestKeywordArguments < Test::Unit::TestCase assert_equal(:ok, many_kwargs(e0: :ok)[i], "#{i}: e0"); i+=1 end + + def test_splat_empty_hash_with_block_passing + assert_valid_syntax("bug15087(**{}, &nil)") + end end