diff options
-rw-r--r-- | hash.c | 4 | ||||
-rw-r--r-- | insns.def | 11 | ||||
-rw-r--r-- | internal.h | 1 | ||||
-rw-r--r-- | test/ruby/test_hash.rb | 13 | ||||
-rw-r--r-- | version.h | 2 |
5 files changed, 23 insertions, 8 deletions
@@ -2504,8 +2504,6 @@ rb_hash_flatten(int argc, VALUE *argv, VALUE hash) return ary; } -static VALUE rb_hash_compare_by_id_p(VALUE hash); - /* * call-seq: * hsh.compare_by_identity -> hsh @@ -2541,7 +2539,7 @@ rb_hash_compare_by_id(VALUE hash) * */ -static VALUE +VALUE rb_hash_compare_by_id_p(VALUE hash) { if (!RHASH(hash)->ntbl) @@ -1950,7 +1950,9 @@ opt_aset_with (VALUE recv, VALUE val) (VALUE val) { - if (!SPECIAL_CONST_P(recv) && RBASIC_CLASS(recv) == rb_cHash && BASIC_OP_UNREDEFINED_P(BOP_ASET, HASH_REDEFINED_OP_FLAG)) { + if (!SPECIAL_CONST_P(recv) && RBASIC_CLASS(recv) == rb_cHash && + BASIC_OP_UNREDEFINED_P(BOP_ASET, HASH_REDEFINED_OP_FLAG) && + rb_hash_compare_by_id_p(recv) == Qfalse) { rb_hash_aset(recv, key, val); } else { @@ -1972,7 +1974,9 @@ opt_aref_with (VALUE recv) (VALUE val) { - if (!SPECIAL_CONST_P(recv) && RBASIC_CLASS(recv) == rb_cHash && BASIC_OP_UNREDEFINED_P(BOP_AREF, HASH_REDEFINED_OP_FLAG)) { + if (!SPECIAL_CONST_P(recv) && RBASIC_CLASS(recv) == rb_cHash && + BASIC_OP_UNREDEFINED_P(BOP_AREF, HASH_REDEFINED_OP_FLAG) && + rb_hash_compare_by_id_p(recv) == Qfalse) { val = rb_hash_aref(recv, key); } else { @@ -2121,8 +2125,7 @@ opt_succ BASIC_OP_UNREDEFINED_P(BOP_SUCC, STRING_REDEFINED_OP_FLAG)) { val = rb_str_succ(recv); } - else - { + else { goto INSN_LABEL(normal_dispatch); } } diff --git a/internal.h b/internal.h index 7a76ba2548..72892cb6cf 100644 --- a/internal.h +++ b/internal.h @@ -715,6 +715,7 @@ long rb_objid_hash(st_index_t index); VALUE rb_ident_hash_new(void); st_table *rb_init_identtable(void); st_table *rb_init_identtable_with_size(st_index_t size); +VALUE rb_hash_compare_by_id_p(VALUE hash); #define RHASH_TBL_RAW(h) rb_hash_tbl_raw(h) VALUE rb_hash_keys(VALUE hash); diff --git a/test/ruby/test_hash.rb b/test/ruby/test_hash.rb index 1bb32f663e..9ac3614dd8 100644 --- a/test/ruby/test_hash.rb +++ b/test/ruby/test_hash.rb @@ -228,6 +228,19 @@ class TestHash < Test::Unit::TestCase assert_same a.keys[0], b.keys[0] end + def test_hash_aset_fstring_identity + h = {}.compare_by_identity + h['abc'] = 1 + h['abc'] = 2 + assert_equal 2, h.size, '[ruby-core:78783] [Bug #12855]' + end + + def test_hash_aref_fstring_identity + h = {}.compare_by_identity + h['abc'] = 1 + assert_nil h['abc'], '[ruby-core:78783] [Bug #12855]' + end + def test_NEWHASH_fstring_key a = {"ABC" => :t} b = {"ABC" => :t} @@ -1,6 +1,6 @@ #define RUBY_VERSION "2.2.7" #define RUBY_RELEASE_DATE "2017-03-26" -#define RUBY_PATCHLEVEL 431 +#define RUBY_PATCHLEVEL 432 #define RUBY_RELEASE_YEAR 2017 #define RUBY_RELEASE_MONTH 3 |