[Bug #2995] TestHash#test_recursive_check fails

Bug #2995: TestHash#test_recursive_check fails
http://redmine.ruby-lang.org/issues/show/2995

e$B5/I<<Te(B: Shugo M.
e$B%9%F!<%?%9e(B: Open, e$BM%@hEYe(B: Normal
e$BC4Ev<Te(B: Nobuyoshi N., e$B%+%F%4%je(B: core, Target version:
1.9.2
ruby -v: ruby 1.9.2dev (2010-03-23 trunk 27020) [i686-linux]

e$BA0ED$G$9!#e(B

e$B0J2<$NJQ99e(B(r26961)e$B$G!“e(BTestHash#test_recursive_checke$B$,<:GT$9$k$h$&$K$J$C$F$$$ke(B
e$B$N$G$9$,!”$3$NJQ99$O0U?^E*$G$7$g$&$+!#e(B

Wed Mar 17 16:25:53 2010 Nobuyoshi N. [email protected]

    * hash.c (rb_hash_aset): allow recursive key.  [ruby-core:24648]

[ruby-core:24648]e$B$r8+$k$H!"e(B

h={}
=> {}
h[:key] = h
=> {:key=>{…}}
h.hash
ArgumentError: recursive key for hash

e$B$N$h$&$KCM$K<+J,<+?H$r4^$`e(BHashe$B$Ne(Bhashe$B%a%=%C%I8F$S=P$7$GNc30$,5/$3$k$H$$$&OC$G!"e(B

h[h] = :foo

e$B$N$h$&$K%-!<$K<+J,<+?H$rM?$($k$H$$$&$N$H$O0c$&OC$N$h$&$KFI$a$^$9!#e(B

e$B$^$?!“e(Btest_recursive_checke$B$K$”$k$h$&$Ke(B

h = {}
h[h] = :foo

e$B$N$h$&$J%3!<%I$r<B9T$7$F$b!"e(Bh[h]e$B$Ge(B:fooe$B$O<hF@$G$-$^$;$s!#e(B
r26961e$B$O$I$&$$$&0U?^$NJQ99$J$N$G$7$g$&$+!#e(B

e$B$J$+$@$G$9!#e(B

At Tue, 23 Mar 2010 19:15:10 +0900,
Shugo M. wrote in [ruby-dev:40735]:

e$B0J2<$NJQ99e(B(r26961)e$B$G!“e(BTestHash#test_recursive_checke$B$,<:GT$9$k$h$&$K$J$C$F$$$ke(B
e$B$N$G$9$,!”$3$NJQ99$O0U?^E*$G$7$g$&$+!#e(B

e$B0l1~0U?^E*$G$9$,!"8!F$ITB-$G$7$?!#e(B

e$B$^$?!“e(Btest_recursive_checke$B$K$”$k$h$&$Ke(B

h = {}
h[h] = :foo

e$B$N$h$&$J%3!<%I$r<B9T$7$F$b!"e(Bh[h]e$B$Ge(B:fooe$B$O<hF@$G$-$^$;$s!#e(B

rehashe$B$9$l$P<hF@$G$-$k$h$&$G$9$,!“%-!<$G:F5”$9$ke(BHashe$B$Oe(Breplacee$B$de(B
updatee$B$G$b:n$l$k$N$G!"%(%i!<$K$9$k$J$i0J2<$N$h$&$K$9$k$Y$-$G$7$ge(B
e$B$&$+!#e(B

r26961e$B$O$I$&$$$&0U?^$NJQ99$J$N$G$7$g$&$+!#e(B

http://twitter.com/lchin/status/10610389214
http://twitter.com/lchin/status/10610640493
e$B$"$?$j$G$9!#e(Br24943e$B$G$NJQ99O3$l$+$H;W$C$?$N$G$9$,!#e(B

diff --git i/hash.c w/hash.c
index 0b863bd…0e4e3dc 100644
— i/hash.c
+++ w/hash.c
@@ -276,4 +276,7 @@ hash_update(VALUE hash, VALUE key)
rb_raise(rb_eRuntimeError, “can’t add a new key into hash during
iteration”);
}

  • if (hash == key) {
  • rb_raise(rb_eArgError, “recursive key for hash”);
  • }
    }

e$BA0ED$G$9!#e(B

2010e$BG/e(B3e$B7ne(B24e$BF|e(B17:08 Nobuyoshi N.
[email protected]:

e$B$N$h$&$J%3!<%I$r<B9T$7$F$b!"e(Bh[h]e$B$Ge(B:fooe$B$O<hF@$G$-$^$;$s!#e(B

rehashe$B$9$l$P<hF@$G$-$k$h$&$G$9$,!“%-!<$G:F5”$9$ke(BHashe$B$Oe(Breplacee$B$de(B
updatee$B$G$b:n$l$k$N$G!"%(%i!<$K$9$k$J$i0J2<$N$h$&$K$9$k$Y$-$G$7$ge(B
e$B$&$+!#e(B

e$B$J$k$[$I!"e(B[]=e$B$NCf$Ge(Bselfe$B$H%-!<$,F1$8%*%V%8%'%/%H$@$C$?;~$O!"e(B[]=e$B$NFbIt$Ge(B
rehashe$B$9$k$H$$$$$s$G$9$+$M!#e(B

r26961e$B$O$I$&$$$&0U?^$NJQ99$J$N$G$7$g$&$+!#e(B

http://twitter.com/lchin/status/10610389214
http://twitter.com/lchin/status/10610640493
e$B$"$?$j$G$9!#e(Br24943e$B$G$NJQ99O3$l$+$H;W$C$?$N$G$9$,!#e(B

Hashe$B$N%-!<$K$9$k$H4m$J$$$b$N$OB>$K$b$“$k$N$G!”$3$N%1!<%9$@$1%(%i!<$Ke(B
e$B$9$kI,MW$b$J$$$+$J$H;W$$$^$9!#e(B
1.8e$B$H$N8_49@-$H$$$&0UL#$G$b%(%i!<$K$7$J$$J}$,$$$$$+$b$7$l$J$$$G$9$M!#e(B

e$B$H$/$K0[O@$,$J$1$l$P!"%F%9%H$NJ}$r=$@5$9$k$H$$$&$3$H$G$I$&$G$7$g$&$+!#e(B

e$BA0ED$G$9!#e(B

2010e$BG/e(B3e$B7ne(B25e$BF|e(B12:17 Shugo M. [email protected]:

Hashe$B$N%-!<$K$9$k$H4m$J$$$b$N$OB>$K$b$“$k$N$G!”$3$N%1!<%9$@$1%(%i!<$Ke(B
e$B$9$kI,MW$b$J$$$+$J$H;W$$$^$9!#e(B
1.8e$B$H$N8_49@-$H$$$&0UL#$G$b%(%i!<$K$7$J$$J}$,$$$$$+$b$7$l$J$$$G$9$M!#e(B

e$B$H$/$K0[O@$,$J$1$l$P!"%F%9%H$NJ}$r=$@5$9$k$H$$$&$3$H$G$I$&$G$7$g$&$+!#e(B

e$B$H$j$"$($:%F%9%H$NJ}$r=$@5$7$F$*$-$^$7$?!#e(B

e$B%A%1%C%He(B #2995 e$B$,99?7$5$l$^$7$?!#e(B (by Shugo M.)

e$B%9%F!<%?%9e(B Opene$B$+$ie(BClosede$B$KJQ99e(B
e$B?JD=e(B % 0e$B$+$ie(B100e$B$KJQ99e(B

This issue was solved with changeset r27062.
Shugo, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.


http://redmine.ruby-lang.org/issues/show/2995