diff options
author | usa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-03-25 15:39:40 +0000 |
---|---|---|
committer | usa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-03-25 15:39:40 +0000 |
commit | d8b81e525658c56992fc7dcc3290e544e08933f0 (patch) | |
tree | 673990fab5a1b34d2912ffa72198585f68ff171a | |
parent | 8dc3d3fd54982480b3bf8ce2e0112bded800b982 (diff) |
merge revision(s) 57360: [Backport #12884]
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]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_2@58092 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | class.c | 3 | ||||
-rw-r--r-- | test/ruby/test_keyword.rb | 12 | ||||
-rw-r--r-- | version.h | 2 |
3 files changed, 16 insertions, 1 deletions
@@ -1914,6 +1914,9 @@ rb_extract_keywords(VALUE *orighash) } 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]; } diff --git a/test/ruby/test_keyword.rb b/test/ruby/test_keyword.rb index 82037575f9..df366845fe 100644 --- a/test/ruby/test_keyword.rb +++ b/test/ruby/test_keyword.rb @@ -603,4 +603,16 @@ class TestKeywordArguments < Test::Unit::TestCase assert_equal({x: 1, y: 2, **h}, obj.foo) } 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 @@ -1,6 +1,6 @@ #define RUBY_VERSION "2.2.7" #define RUBY_RELEASE_DATE "2017-03-26" -#define RUBY_PATCHLEVEL 424 +#define RUBY_PATCHLEVEL 425 #define RUBY_RELEASE_YEAR 2017 #define RUBY_RELEASE_MONTH 3 |