summaryrefslogtreecommitdiff
path: root/hash.c
diff options
context:
space:
mode:
authorJeremy Evans <code@jeremyevans.net>2022-11-09 09:37:04 -0800
committerJeremy Evans <code@jeremyevans.net>2023-03-24 10:55:13 -0700
commit1b13db25d8ed0f328acc4e86668f8ad7deae7221 (patch)
treef642a812e98c7c749bacb3be101205e179194bfc /hash.c
parentd3197def882b47e7c57cdddfe8d62f62fef9d3f7 (diff)
downloadruby-1b13db25d8ed0f328acc4e86668f8ad7deae7221.tar.gz
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]
Diffstat (limited to 'hash.c')
-rw-r--r--hash.c9
1 files changed, 6 insertions, 3 deletions
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 {