summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--hash.c1
-rw-r--r--test/ruby/test_hash.rb9
2 files changed, 10 insertions, 0 deletions
diff --git a/hash.c b/hash.c
index 2cfdbad69b..27111685dc 100644
--- a/hash.c
+++ b/hash.c
@@ -3303,6 +3303,7 @@ transform_values_foreach_replace(st_data_t *key, st_data_t *value, st_data_t arg
{
VALUE new_value = rb_yield((VALUE)*value);
VALUE hash = (VALUE)argp;
+ rb_hash_modify(hash);
RB_OBJ_WRITE(hash, value, new_value);
return ST_CONTINUE;
}
diff --git a/test/ruby/test_hash.rb b/test/ruby/test_hash.rb
index a6acbc6054..bd94b408bb 100644
--- a/test/ruby/test_hash.rb
+++ b/test/ruby/test_hash.rb
@@ -1803,6 +1803,15 @@ class TestHash < Test::Unit::TestCase
x = @cls[a: 1, b: 2, c: 3]
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))
+
+ x = @cls[a: 1, b: 2, c: 3, d: 4, e: 5, f: 6, g: 7, h: 8, i: 9, j: 10]
+ assert_raise(FrozenError) do
+ x.transform_values!() do |v|
+ x.freeze if v == 2
+ v.succ
+ end
+ end
+ assert_equal(@cls[a: 2, b: 2, c: 3, d: 4, e: 5, f: 6, g: 7, h: 8, i: 9, j: 10], x)
end
def test_broken_hash_value