From 6531343242e28b179e6d3d25af3b7fb65c90b66b Mon Sep 17 00:00:00 2001 From: Andrii Furmanets Date: Wed, 4 Mar 2026 16:41:27 +0200 Subject: weakmap: return assigned value from #[]= and add regression test --- test/ruby/test_weakmap.rb | 7 +++++++ weakmap.c | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/test/ruby/test_weakmap.rb b/test/ruby/test_weakmap.rb index 4f5823ecf4..2f5c747339 100644 --- a/test/ruby/test_weakmap.rb +++ b/test/ruby/test_weakmap.rb @@ -39,6 +39,13 @@ class TestWeakMap < Test::Unit::TestCase assert_same(:foo, @wm[x]) end + def test_aset_returns_value + key = Object.new + value = Object.new + + assert_same(value, @wm.send(:[]=, key, value)) + end + def assert_weak_include(m, k, n = 100) if n > 0 return assert_weak_include(m, k, n-1) diff --git a/weakmap.c b/weakmap.c index 80ef29b4cc..7cef1fd46a 100644 --- a/weakmap.c +++ b/weakmap.c @@ -394,7 +394,7 @@ wmap_aset(VALUE self, VALUE key, VALUE val) RB_OBJ_WRITTEN(self, Qundef, key); RB_OBJ_WRITTEN(self, Qundef, val); - return Qnil; + return val; } /* Retrieves a weakly referenced object with the given key */ -- cgit v1.2.3