diff options
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | hash.c | 5 | ||||
-rw-r--r-- | test/ruby/test_hash.rb | 9 |
3 files changed, 19 insertions, 1 deletions
@@ -1,3 +1,9 @@ +Thu Oct 18 09:23:03 2012 Aaron Patterson <aaron@tenderlovemaking.com> + + * hash.c (initialize_copy): duping should rehash the hash. + + * test/ruby/test_hash.rb: added a test to ensure rehash. + Wed Oct 17 21:16:47 2012 Hiroshi Shirosaki <h.shirosaki@gmail.com> * common.mk (WPROGRAM): need same dependencies as PROGRAM. @@ -1187,8 +1187,11 @@ rb_hash_initialize_copy(VALUE hash, VALUE hash2) { Check_Type(hash2, T_HASH); - if (!RHASH_EMPTY_P(hash2)) + if (!RHASH_EMPTY_P(hash2)) { RHASH(hash)->ntbl = st_copy(RHASH(hash2)->ntbl); + rb_hash_rehash(hash); + } + if (FL_TEST(hash2, HASH_PROC_DEFAULT)) { FL_SET(hash, HASH_PROC_DEFAULT); } diff --git a/test/ruby/test_hash.rb b/test/ruby/test_hash.rb index f1eef88d99..076146f5a4 100644 --- a/test/ruby/test_hash.rb +++ b/test/ruby/test_hash.rb @@ -100,6 +100,15 @@ class TestHash < Test::Unit::TestCase assert_raises(TypeError) { h.dup } end + def test_dup_will_rehash + set1 = { } + set2 = { set1 => true} + + set1[set1] = true + + assert_equal set2, set2.dup + end + def test_s_AREF h = @cls["a" => 100, "b" => 200] assert_equal(100, h['a']) |