diff options
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | compile.c | 1 | ||||
-rw-r--r-- | test/ruby/test_keyword.rb | 13 |
3 files changed, 20 insertions, 0 deletions
@@ -1,3 +1,9 @@ +Sat Apr 26 10:55:33 2014 Nobuyoshi Nakada <nobu@ruby-lang.org> + + * compile.c (compile_array_): make copy a first hash not to modify + the argument itself. keyword splat should be non-destructive. + [ruby-core:62161] [Bug #9776] + Sat Apr 26 08:05:36 2014 Tanaka Akira <akr@fsij.org> * test/ruby/test_process.rb (test_rlimit_nofile): Don't limit @@ -2479,6 +2479,7 @@ compile_array_(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE* node_root, if (i > 0 || !first) ADD_INSN(ret, line, swap); COMPILE(ret, "keyword splat", kw); ADD_SEND(ret, line, ID2SYM(id_core_hash_merge_kwd), nhash); + if (nhash == INT2FIX(1)) ADD_SEND(ret, line, ID2SYM(rb_intern("dup")), INT2FIX(0)); } first = 0; break; diff --git a/test/ruby/test_keyword.rb b/test/ruby/test_keyword.rb index 31830dfb2f..5988905138 100644 --- a/test/ruby/test_keyword.rb +++ b/test/ruby/test_keyword.rb @@ -439,6 +439,19 @@ class TestKeywordArguments < Test::Unit::TestCase assert_equal([1, 2, 1, [], {:f=>5}, 2, {}], a.new.foo(1, 2, f:5), bug8993) end + def test_splat_keyword_nondestructive + bug9776 = '[ruby-core:62161] [Bug #9776]' + + h = {a: 1} + assert_equal({a:1, b:2}, {**h, b:2}) + assert_equal({a:1}, h, bug9776) + + pr = proc {|**opt| next opt} + assert_equal({a: 1}, pr.call(**h)) + assert_equal({a: 1, b: 2}, pr.call(**h, b: 2)) + assert_equal({a: 1}, h, bug9776) + end + def test_gced_object_in_stack bug8964 = '[ruby-dev:47729] [Bug #8964]' assert_normal_exit %q{ |