Skip to content

Commit 9bd802f

Browse files
committed
gc.c: fix WeakMap#inspect
* gc.c (wmap_inspect_i): fix key/value order. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44107 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
1 parent 332decb commit 9bd802f

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

gc.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -6346,8 +6346,8 @@ wmap_inspect(VALUE self)
63466346

63476347
TypedData_Get_Struct(self, struct weakmap, &weakmap_type, w);
63486348
str = rb_sprintf("-<%"PRIsVALUE":%p", c, (void *)self);
6349-
if (w->obj2wmap) {
6350-
st_foreach(w->obj2wmap, wmap_inspect_i, str);
6349+
if (w->wmap2obj) {
6350+
st_foreach(w->wmap2obj, wmap_inspect_i, str);
63516351
}
63526352
RSTRING_PTR(str)[0] = '#';
63536353
rb_str_cat2(str, ">");

test/ruby/test_weakmap.rb

+8
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,14 @@ def test_include?
2828
alias test_member? test_include?
2929
alias test_key? test_include?
3030

31+
def test_inspect
32+
x = Object.new
33+
k = BasicObject.new
34+
@wm[k] = x
35+
assert_match(/\A\#<#{@wm.class.name}:[^:]+:\s\#<BasicObject:[^:]*>\s=>\s\#<Object:[^:]*>>\z/,
36+
@wm.inspect)
37+
end
38+
3139
def test_each
3240
m = __callee__[/test_(.*)/, 1]
3341
x1 = Object.new

0 commit comments

Comments
 (0)