ruby-changes:34261
From: nobu <ko1@a...>
Date: Wed, 4 Jun 2014 04:08:46 +0900 (JST)
Subject: [ruby-changes:34261] nobu:r46342 (trunk): vm.c: return the result hash
nobu 2014-06-04 04:08:40 +0900 (Wed, 04 Jun 2014) New Revision: 46342 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=46342 Log: vm.c: return the result hash * vm.c (core_hash_merge_kwd): should return the result hash, which may be converted from and differ from the given argument. [ruby-core:62921] [Bug #9898] Modified files: trunk/ChangeLog trunk/test/ruby/test_keyword.rb trunk/vm.c Index: ChangeLog =================================================================== --- ChangeLog (revision 46341) +++ ChangeLog (revision 46342) @@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Wed Jun 4 04:08:37 2014 Nobuyoshi Nakada <nobu@r...> + + * vm.c (core_hash_merge_kwd): should return the result hash, which + may be converted from and differ from the given argument. + [ruby-core:62921] [Bug #9898] + Tue Jun 3 23:32:34 2014 Tanaka Akira <akr@f...> * ruby.c (load_file_internal2): Extracted from load_file_internal. Index: vm.c =================================================================== --- vm.c (revision 46341) +++ vm.c (revision 46342) @@ -2357,6 +2357,7 @@ core_hash_merge_kwd(int argc, VALUE *arg https://github.com/ruby/ruby/blob/trunk/vm.c#L2357 hash = argv[0]; kw = argv[argc-1]; kw = rb_convert_type(kw, T_HASH, "Hash", "to_hash"); + if (argc < 2) hash = kw; rb_hash_foreach(kw, argc < 2 ? kwcheck_i : kwmerge_i, hash); return hash; } Index: test/ruby/test_keyword.rb =================================================================== --- test/ruby/test_keyword.rb (revision 46341) +++ test/ruby/test_keyword.rb (revision 46342) @@ -452,6 +452,17 @@ class TestKeywordArguments < Test::Unit: https://github.com/ruby/ruby/blob/trunk/test/ruby/test_keyword.rb#L452 assert_equal({a: 1}, h, bug9776) end + def test_splat_hash_conversion + bug9898 = '[ruby-core:62921] [Bug #9898]' + + o = Object.new + def o.to_hash() { a: 1 } end + assert_equal({a: 1}, m1(**o) {|x| break x}, bug9898) + o2 = Object.new + def o2.to_hash() { b: 2 } end + assert_equal({a: 1, b: 2}, m1(**o, **o2) {|x| break x}, bug9898) + end + def test_gced_object_in_stack bug8964 = '[ruby-dev:47729] [Bug #8964]' assert_normal_exit %q{ -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/