summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeremy Evans <code@jeremyevans.net>2020-09-21 15:02:20 -0700
committerJeremy Evans <code@jeremyevans.net>2020-09-21 19:35:08 -0700
commitdf14c758fc705c49c2aaf4c9276a8f7229438fbf (patch)
tree49ef6a8a7885a5712e4bac94c99f861ab955f05e
parent7ee166ed4e8da7677d7b7f4706907eac89af4da6 (diff)
Make hash returned by Hash#transform_values not have a default
This sets an explicit default of nil. There is probably a better approach of removing the default. Fixes [Bug #17181]
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/3563
-rw-r--r--hash.c1
-rw-r--r--test/ruby/test_hash.rb1
2 files changed, 2 insertions, 0 deletions
diff --git a/hash.c b/hash.c
index c20ceb329b..2ccf8ec014 100644
--- a/hash.c
+++ b/hash.c
@@ -3350,6 +3350,7 @@ rb_hash_transform_values(VALUE hash)
RETURN_SIZED_ENUMERATOR(hash, 0, 0, hash_enum_size);
result = hash_copy(hash_alloc(rb_cHash), hash);
+ SET_DEFAULT(result, Qnil);
if (!RHASH_EMPTY_P(hash)) {
rb_hash_stlike_foreach_with_replace(result, transform_values_foreach_func, transform_values_foreach_replace, result);
diff --git a/test/ruby/test_hash.rb b/test/ruby/test_hash.rb
index e63fdf32fd..91e14daf2c 100644
--- a/test/ruby/test_hash.rb
+++ b/test/ruby/test_hash.rb
@@ -1696,6 +1696,7 @@ class TestHash < Test::Unit::TestCase
x.default_proc = proc {|h, k| k}
y = x.transform_values {|v| v ** 2 }
assert_nil(y.default_proc)
+ assert_nil(y.default)
y = x.transform_values.with_index {|v, i| "#{v}.#{i}" }
assert_equal(%w(1.0 2.1 3.2), y.values_at(:a, :b, :c))