[Bug #2658] rubyspec: Ruby character strings interpolates the return value of Object#inspect, withou

Bug #2658: rubyspec: Ruby character strings interpolates the return
value of Object#inspect, without ivars, if Object#to_s does not return a
String instance ERROR
http://redmine.ruby-lang.org/issues/show/2658

e$B5/I<<Te(B: Yusuke E.
e$B%9%F!<%?%9e(B: Open, e$BM%@hEYe(B: Normal
e$BC4Ev<Te(B: Yukihiro M., e$B%+%F%4%je(B: core, Target version:
1.9.2
ruby -v: ruby 1.9.2dev (2010-01-26 trunk 26425) [i686-linux]

e$B$^$D$b$H$5$se(B
e$B1sF#$G$9!#e(B

rubyspec e$B$N0J2<$N%(%i!<$rD4$Y$F$_$^$7$?!#e(B

Ruby character strings interpolates the return value of Object#inspect,
without ivars, if Object#to_s does not return a String instance ERROR
ArgumentError: wrong number of arguments(2 for 1)
/home/mame/work/ruby/spec/rubyspec/language/string_spec.rb:158:in []' /home/mame/work/ruby/spec/rubyspec/language/string_spec.rb:158:inblock
(2 levels) in <top (required)>’
/home/mame/work/ruby/spec/rubyspec/language/string_spec.rb:5:in `<top
(required)>’

r25428 e$B$,860x$G$9!#$3$N%3%_%C%H$G$O!"e(B

  • rdoc e$B$NJ8>O$,2u$l$F$$$^$9!#e(B

  • rdoc e$B$K$h$k$H!"!Ve(Bto_s e$B$,e(B override e$B$5$l$Fe(B
    e$B$$$J$$e(B e$B$H$-$Oe(B to_s e$B$r;H$&!We(B
    e$B$H$$$&;[email protected]$H;W$$$^$9$,!"8=:_$Oe(B to_s e$B$,e(B override
    e$B$5$l$Fe(B e$B$$$ke(B e$B$H$-$Ke(B
    to_s e$B$r;H$&$h$&$K$J$C$F$$$k$H;W$$$^$9!#e(B

    $ ./ruby -ve ’
    class C
    def to_s; “overridden”; end
    end
    p C.new

    ruby 1.9.2dev (2010-01-26 trunk 26425) [i686-linux]
    overridden

e$B$H$$$&$3$H$G!"0J2<$N%Q%C%A$r%3%_%C%H$r$7$F$b$$$$$G$7$g$&$+!#e(B
e$B$3$N%Q%C%A$K$h$C$F>e5-$Ne(B rubyspec
e$B$N%(%i!<$,>C$($k$3$H$r3NG’$7$F$$$^$9!#e(B

diff --git a/object.c b/object.c
index 73e5bd1…441f226 100644
— a/object.c
+++ b/object.c
@@ -367,8 +367,6 @@ inspect_obj(VALUE obj, VALUE str, int recur)

  • obj.inspect   => string
    
  • Returns a string containing a human-readable representation of
    • obj. If not overridden and no instance variables, uses the
    • to_s method to generate the string.
    • obj. If not overridden, uses the to_s method
      to
    • generate the string.

@@ -381,7 +379,7 @@ extern int rb_obj_basic_to_s_p(VALUE);
static VALUE
rb_obj_inspect(VALUE obj)
{

  • if (TYPE(obj) == T_OBJECT && rb_obj_basic_to_s_p(obj)) {
  • if (TYPE(obj) == T_OBJECT && !rb_obj_basic_to_s_p(obj)) {
    int has_ivar = 0;
    VALUE *ptr = ROBJECT_IVPTR(obj);
    long len = ROBJECT_NUMIV(obj);


Yusuke ENDOH [email protected]

2010e$BG/e(B1e$B7ne(B26e$BF|e(B20:39 Yusuke E.
[email protected]:

r25428 e$B$,860x$G$9!#$3$N%3%_%C%H$G$O!"e(B

  • rdoc e$B$NJ8>O$,2u$l$F$$$^$9!#e(B

  • rdoc e$B$K$h$k$H!"!Ve(Bto_s e$B$,e(B override e$B$5$l$Fe(B e$B$$$J$$e(B e$B$H$-$Oe(B to_s e$B$r;H$&!We(B
    e$B$H$$$&;[email protected]$H;W$$$^$9$,!"8=:_$Oe(B to_s e$B$,e(B override e$B$5$l$Fe(B e$B$$$ke(B e$B$H$-$Ke(B
    to_s e$B$r;H$&$h$&$K$J$C$F$$$k$H;W$$$^$9!#e(B

override e$B$5$l$F$ke(B to_s e$B$O3F%/%i%9$KFC2=$7$?$o$+$j$d$9$$e(B to_s
[email protected]$m$&$+$ie(B
inspect e$B$H$7$F$O$=$C$A$r;H$&$C$F$$$&OC$J$s$8$c$J$$$G$9$+!#e(B

e$B$=$l$K!"e(Boverride e$B$5$l$F$$$J$$$H$-$Ke(B to_s
e$B$r;H$&$C$F$$$&$J$i!“e(B
e$B%a%=%C%I8F$S=P$7$rDL$7$Fe(B dynamic binding
e$B$K$9$k0UL#$O$”$j$^$;$s$h$M!#e(B

2010e$BG/e(B1e$B7ne(B26e$BF|e(B21:49 Tanaka A. [email protected]:

override e$B$5$l$F$ke(B to_s e$B$O3F%/%i%9$KFC2=$7$?$o$+$j$d$9$$e(B to_s [email protected]$m$&$+$ie(B
inspect e$B$H$7$F$O$=$C$A$r;H$&$C$F$$$&OC$J$s$8$c$J$$$G$9$+!#e(B

e$B$=$l$K!"e(Boverride e$B$5$l$F$$$J$$$H$-$Ke(B to_s e$B$r;H$&$C$F$$$&$J$i!“e(B
e$B%a%=%C%I8F$S=P$7$rDL$7$Fe(B dynamic binding e$B$K$9$k0UL#$O$”$j$^$;$s$h$M!#e(B

e$B3N$+$K!#$=$&$$$&$3$H$J$i!"e(Brdoc e$B$N4V0c$$$G$9$+$M!#e(B

diff --git a/object.c b/object.c
index 73e5bd1…ab00efd 100644
— a/object.c
+++ b/object.c
@@ -367,10 +367,8 @@ inspect_obj(VALUE obj, VALUE str, int recur)

  • obj.inspect   => string
    
  • Returns a string containing a human-readable representation of
    • obj. If not overridden and no instance variables, uses the
    • obj. If to_s<\code> is overridden, uses the
    • to_s method to generate the string.
    • obj. If not overridden, uses the to_s method
      to
    • generate the string.
    • [ 1, 2, 3..4, 'five' ].inspect   #=> "[1, 2, 3..4, \"five\"]"
      
    • Time.new.inspect                 #=> "2008-03-08 19:43:39 +0900"
      

e$B5sF0$O8=>u$N$^$^$K$9$k$H$7$F!"e(B

  1. e$B$3$N5sF0$Oe(B 1.9.2 e$B$+$i$N;EMMJQ99e(B (1.9.1 e$B$O$=$N$^$^e(B)
  2. e$B$3$N5sF0$Oe(B 1.9 e$B$+$i$N;EMMJQ99e(B (1.9.1
    e$B$K$b%P%C%/%]!<%H$9$ke(B)
  3. e$B$3$N5sF0$Oe(B 1.8/1.9 e$B$N;EMMe(B (1.8.x
    e$B$K$b%P%C%/%]!<%H$9$ke(B)

e$B$N$I$l$H$9$Y$-$G$7$g$&$+!#e(Brubyspec
[email protected]$NFbMF$K1F6A$7$^$9!#e(B

(1.8 e$B$Ne(B rb_obj_inspect e$B$Ne(B rdoc
e$B$H5sF0$,$"$C$F$J$$$N$G!"e(B1.8 e$B$K$be(B
[email protected]$,I,[email protected]$H;W$$$^$9!#e(B)

e$B$^$D$b$He(B e$B$f$-$R$m$G$9e(B

In message “Re: [ruby-dev:40164] Re: [Bug #2658] rubyspec: Ruby
character strings interpolates the return value of Object#inspect,
without ivars, if Object#to_s does not return a String instance ERROR”
on Tue, 26 Jan 2010 22:41:55 +0900, Yusuke ENDOH [email protected]
writes:

|> override e$B$5$l$F$ke(B to_s e$B$O3F%/%i%9$KFC2=$7$?$o$+$j$d$9$$e(B to_s [email protected]$m$&$+$ie(B
|> inspect e$B$H$7$F$O$=$C$A$r;H$&$C$F$$$&OC$J$s$8$c$J$$$G$9$+!#e(B

|e$B3N$+$K!#$=$&$$$&$3$H$J$i!"e(Brdoc e$B$N4V0c$$$G$9$+$M!#e(B

e$B$"!<!"$=$&$$$&$3$H$+!#4V0c$C$F$k$N$Oe(BRDoce$B$NJ}$G$9$M!#e(B

|e$B5sF0$O8=>u$N$^$^$K$9$k$H$7$F!"e(B
|
|1. e$B$3$N5sF0$Oe(B 1.9.2 e$B$+$i$N;EMMJQ99e(B (1.9.1 e$B$O$=$N$^$^e(B)
|2. e$B$3$N5sF0$Oe(B 1.9 e$B$+$i$N;EMMJQ99e(B (1.9.1 e$B$K$b%P%C%/%]!<%H$9$ke(B)
|3. e$B$3$N5sF0$Oe(B 1.8/1.9 e$B$N;EMMe(B (1.8.x e$B$K$b%P%C%/%]!<%H$9$ke(B)
|
|e$B$N$I$l$H$9$Y$-$G$7$g$&$+!#e(Brubyspec [email protected]$NFbMF$K1F6A$7$^$9!#e(B

1e$B$^$?$Oe(B2e$B$G$7$g$&$M!#$I$A$i$K$9$k$+$Oe(BYuguie$B$5$s$K$*G$$;$7$^$9!#e(B

On 1/27/10 6:29 PM, Yukihiro M. wrote:

|挙動は現状のままにするとして、
|
|1. この挙動は 1.9.2 からの仕様変更 (1.9.1 はそのまま)
|2. この挙動は 1.9 からの仕様変更 (1.9.1 にもバックポートする)
|3. この挙動は 1.8/1.9 の仕様 (1.8.x にもバックポートする)
|
|のどれとすべきでしょうか。rubyspec ã®ä¿®æ­£ä¾é ¼ã®å†…å®¹ã«å½±éŸ¿ã—ã¾ã™ã€‚

1または2でしょうね。どちらにするかはYuguiさんにお任せします。

1にします。そしてrubyspecを添付のpatchのように変更することを提案します。
理由としては

  • 1.8ã‚„1.9.1の挙動を今更意味なく変えるのは反対です。
  • 1.9.2のポリシーは、それはそれで肯けるので、ならば挙動は維持してrdocã‚’
    合わせましょう。
  • inspectが何を表示するかは実装依存であるべきです。rb_any_to_s、つまり
    デフォルトのto_sとも独立であるべきです。
    • 当該のspecはrb_any_to_sとinspectを混同しています。

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

2010e$BG/e(B1e$B7ne(B30e$BF|e(B13:52 Yugui (Yuki S.)
removed_emai[email protected]:

1e$B$K$7$^$9!#$=$7$Fe(Brubyspece$B$rE:IU$Ne(Bpatche$B$N$h$&$KJQ99$9$k$3$H$rDs0F$7$^$9!#e(B

e$B$"$j$,$H$&$4$6$$$^$9!#$=$7$Fe(B patch e$B$K;[email protected]$7$^$9!#e(B

e$BM}M3$H$7$F$Oe(B

  • 1.8e$B$de(B1.9.1e$B$N5sF0$r:#990UL#$J$/JQ$($k$N$OH?BP$G$9!#e(B
  • 1.9.2e$B$N%]%j%7!<$O!"$=$l$O$=$l$G9N$1$k$N$G!"$J$i$P5sF0$O0];}$7$Fe(Brdoce$B$re(B
    e$B9g$o$;$^$7$g$&!#e(B

1.9.2 e$B$+$i$N;EMMJQ99$H$$$&$N$KB?>/Dq93$O$"$j$^$9$,!"N;2r$G$9!#e(B

  • inspecte$B$,2?$rI=<($9$k$+$O<BAu0MB8$G$"$k$Y$-$G$9!#e(Brb_any_to_se$B!"$D$^$je(B
    e$B%G%U%)%k%H$Ne(Bto_se$B$H$bFHN)$G$"$k$Y$-$G$9!#e(B
  • e$BEv3:$Ne(Bspece$B$Oe(Brb_any_to_se$B$He(Binspecte$B$r:.F1$7$F$$$^$9!#e(B

e$B:.F1$H$$$&$+!“e(Brdoc e$B$rL5;k$7$Fe(B rb_obj_inspect
e$B$N<BAu$r$^$k$4$He(B spec e$B$Ke(B
e$B$7$?$s$G$7$g$&$M!#e(B
inspect e$B$O$[$+$K$b$=$3$i$8$e$&$Ge(B spec
e$B$K$5$l$F$7$^$C$F$$$k$N$G!”$$$:$le(B
e$BD>$5$J$$$H!"$H;W$$$^$9!#e(B

human-readable representation e$B$H$$$&$N$O5!3#H=Dj$G$-$J$$$1$l$I!"e(B

  • ASCII-8BIT e$B0J30$N%(%s%3!<%G%#%s%0$G!"e(Bvalid_encoding? e$B$,e(B
    true e$B$K$J$ke(B

e$B$/$i$$$O;EMM$K$7$F$b$$$$5$$,$9$k!#e(B

Yugui e$B$5$se(B
e$B1sF#$G$9!#e(B

2010e$BG/e(B1e$B7ne(B30e$BF|e(B20:36 Yusuke ENDOH [email protected]:

1e$B$^$?$Oe(B2e$B$G$7$g$&$M!#$I$A$i$K$9$k$+$Oe(BYuguie$B$5$s$K$*G$$;$7$^$9!#e(B

1e$B$K$7$^$9!#$=$7$Fe(Brubyspece$B$rE:IU$Ne(Bpatche$B$N$h$&$KJQ99$9$k$3$H$rDs0F$7$^$9!#e(B

e$B$"$j$,$H$&$4$6$$$^$9!#$=$7$Fe(B patch e$B$K;[email protected]$7$^$9!#e(B

e$B$3$N%Q%C%A$re(B commit + push [email protected]$1$^$9$+!)e(B
e$B$*K;$7$$$h$&$J$i!"5v2D$5$($b$i$($l$P;d$,$d$C$F$b$$$$$G$9!#e(B

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

2010e$BG/e(B2e$B7ne(B9e$BF|e(B21:42 Yusuke ENDOH [email protected]:

e$B$3$N%Q%C%A$re(B commit + push [email protected]$1$^$9$+!)e(B
e$B$*K;$7$$$h$&$J$i!"5v2D$5$($b$i$($l$P;d$,$d$C$F$b$$$$$G$9!#e(B

IRC [email protected]$$$?$N$G!"%3%_%C%H$7$^$7$?!#e(B

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs