summaryrefslogtreecommitdiff
path: root/test/ruby/test_weakmap.rb
diff options
context:
space:
mode:
authorJean Boussier <byroot@ruby-lang.org>2023-03-16 08:52:22 +0000
committerJean Boussier <jean.boussier@gmail.com>2023-03-17 17:50:08 +0000
commit3592b24cdc07ed89eecb39161f21fe721a89a5de (patch)
treec0a5145f22896189dd873922e5dfc7e6ce637f85 /test/ruby/test_weakmap.rb
parentccd2dbc4c15ffb5bde0141a98ec02603c1597243 (diff)
ObjectSpace::WeakMap: clean inverse reference when an entry is re-assigned
[Bug #19531] ```ruby wmap[1] = "A" wmap[1] = "B" ``` In the example above, we need to remove the `"A" => 1` inverse reference so that when `"A"` is GCed the `1` key isn't deleted.
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/7540
Diffstat (limited to 'test/ruby/test_weakmap.rb')
-rw-r--r--test/ruby/test_weakmap.rb17
1 files changed, 17 insertions, 0 deletions
diff --git a/test/ruby/test_weakmap.rb b/test/ruby/test_weakmap.rb
index 9bbe2d6b81..c72e7310db 100644
--- a/test/ruby/test_weakmap.rb
+++ b/test/ruby/test_weakmap.rb
@@ -194,4 +194,21 @@ class TestWeakMap < Test::Unit::TestCase
GC.compact
end;
end
+
+ def test_replaced_values_bug_19531
+ a = "A".dup
+ b = "B".dup
+
+ @wm[1] = a
+ @wm[1] = a
+ @wm[1] = a
+
+ @wm[1] = b
+ assert_equal b, @wm[1]
+
+ a = nil
+ GC.start
+
+ assert_equal b, @wm[1]
+ end
end