From 1b13db25d8ed0f328acc4e86668f8ad7deae7221 Mon Sep 17 00:00:00 2001 From: Jeremy Evans Date: Wed, 9 Nov 2022 09:37:04 -0800 Subject: Copy compare_by_identity flag for empty hashes in Hash.ruby2_keywords_hash This was already copied for non-empty hashes. As Hash.ruby2_keywords_hash copies default values, it should also copy the compare_by_identity flag. Partially Fixes [Bug #19113] --- hash.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'hash.c') diff --git a/hash.c b/hash.c index 40866509d1..285a13494a 100644 --- a/hash.c +++ b/hash.c @@ -1972,9 +1972,12 @@ static VALUE rb_hash_s_ruby2_keywords_hash(VALUE dummy, VALUE hash) { Check_Type(hash, T_HASH); - hash = rb_hash_dup(hash); - RHASH(hash)->basic.flags |= RHASH_PASS_AS_KEYWORDS; - return hash; + VALUE tmp = rb_hash_dup(hash); + if (RHASH_EMPTY_P(hash) && rb_hash_compare_by_id_p(hash)) { + rb_hash_compare_by_id(tmp); + } + RHASH(tmp)->basic.flags |= RHASH_PASS_AS_KEYWORDS; + return tmp; } struct rehash_arg { -- cgit v1.2.1