ruby-changes:45288
From: nobu <ko1@a...>
Date: Wed, 18 Jan 2017 12:39:00 +0900 (JST)
Subject: [ruby-changes:45288] nobu:r57360 (trunk): class.c: non-keyword hash class
nobu 2017-01-18 12:38:52 +0900 (Wed, 18 Jan 2017) New Revision: 57360 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=57360 Log: class.c: non-keyword hash class * class.c (rb_extract_keywords): keep the class of non-keyword elements hash as the original. [ruby-core:77813] [Bug #12884] Modified files: trunk/class.c trunk/test/ruby/test_keyword.rb Index: class.c =================================================================== --- class.c (revision 57359) +++ class.c (revision 57360) @@ -1841,6 +1841,9 @@ rb_extract_keywords(VALUE *orighash) https://github.com/ruby/ruby/blob/trunk/class.c#L1841 } st_foreach(rb_hash_tbl_raw(hash), separate_symbol, (st_data_t)&parthash); *orighash = parthash[1]; + if (parthash[1] && RBASIC_CLASS(hash) != rb_cHash) { + RBASIC_SET_CLASS(parthash[1], RBASIC_CLASS(hash)); + } return parthash[0]; } Index: test/ruby/test_keyword.rb =================================================================== --- test/ruby/test_keyword.rb (revision 57359) +++ test/ruby/test_keyword.rb (revision 57360) @@ -629,4 +629,16 @@ class TestKeywordArguments < Test::Unit: https://github.com/ruby/ruby/blob/trunk/test/ruby/test_keyword.rb#L629 klass.new(d: 4) end end + + def test_non_keyword_hash_subclass + bug12884 = '[ruby-core:77813] [Bug #12884]' + klass = EnvUtil.labeled_class("Child", Hash) + obj = Object.new + def obj.t(params = klass.new, d: nil); params; end + x = klass.new + x["foo"] = "bar" + result = obj.t(x) + assert_equal(x, result) + assert_kind_of(klass, result, bug12884) + end end -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/