From: Joseph Jones Date: 2015-12-17T21:07:10-07:00 Subject: [ruby-core:72299] [Ruby trunk - Bug #11826] [Assigned] After prepending a module, rewrite Hash#[] takes no effect for calls like Hash.new[:a] --5673866e_77ae35eb_16c Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Joseph Jones liked your message with Boxer. On December 16, 2015 at 18:23= :40 MST, shugo=40ruby-lang.org wrote:Issue =2311826 has been updated by S= hugo Maeda.Status changed from Open to AssignedAssignee set to Koichi Sas= adacichol tsai wrote:> It seems like an issue only for =5B=5D method, may= be something about syntax.> But if use 'include' instead of 'prepend', th= e 'h=5B:a=5D' can give an output.> Please help me check if it is a bug, s= orry for bothering.It seems that redefinition check of optimized methods = doesn't work properly for prepended classes.Is the following patch correc= t, ko1=3F=60=60=60diffdiff --git a/vm.c b/vm.cindex a03e068..cf528e8 1006= 44--- a/vm.c+++ b/vm.c=40=40 -1400,6 +1400,9 =40=40 static void rb=5Fvm=5F= check=5Fredefinition=5Fopt=5Fmethod(const rb=5Fmethod=5Fentry=5Ft *me, VA= LUE klass) =7B st=5Fdata=5Ft bop;+ if (RB=5FTYPE=5FP(klass, T=5FICLASS) &= & =46L=5FTEST(klass, RICLASS=5FIS=5FORIGIN)) =7B+ klass =3D RBASIC=5FCLAS= S(klass);+ =7D if (me->def->type =3D=3D VM=5FMETHOD=5FTYPE=5FC=46UNC) =7B= if (st=5Flookup(vm=5Fopt=5Fmethod=5Ftable, (st=5Fdata=5Ft)me, &bop)) =7B= int flag =3D vm=5Fredefinition=5Fcheck=5Fflag(klass);=60=60=60----------= ------------------------------Bug =2311826: After prepending a module, re= write Hash=23=5B=5D takes no effect for calls like Hash.new=5B:a=5Dhttps:= //bugs.ruby-lang.org/issues/11826=23change-55609* Author: cichol tsai* St= atus: Assigned* Priority: Normal* Assignee: Koichi Sasada* ruby -v: ruby = 2.2.2p95 (2015-04-13 revision 50295) =5Bx64-mingw32=5D* Backport: 2.0.0: = UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN--------------------------------------= --=7E=7E=7Emodule M def self.prepended(clz) clz.class=5Feval do def =5B=5D= (k) p 1 end end endendmodule N def self.included(clz) clz.class=5Feval do= def =5B=5D=3D(k, v) p 2 end end endendclass Hash prepend M include Nend= Hash.new=5B1=5DHash.new=5B1=5D=3D1=7E=7E=7ERunning this example gives no = output, which is expected to be '1 2'.I am using 'ruby 2.2.2p95 (2015-04-= 13 revision 50295) =5Bx64-mingw32=5D'.Thanks in advanced.-- https://bugs.= ruby-lang.org/ --5673866e_77ae35eb_16c Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Joseph Jones liked your message with Boxer.


= On December 16, 2015 at 18:23:40 MST, shugo=40ruby-lang.org wrote:
Issue =2311826 has been upda= ted by Shugo Maeda.

Status changed from Open to Assigned
= Assignee set to Koichi Sasada

cichol tsai wrote:
> It see= ms like an issue only for =5B=5D method, maybe something about syntax.> But if use 'include' instead of 'prepend', the 'h=5B:a=5D' can give = an output.
> Please help me check if it is a bug, sorry for botherin= g.

It seems that redefinition check of optimized methods doesn= 't work properly for prepended classes.
Is the following patch corre= ct, ko1=3F

=60=60=60diff
diff --git a/vm.c b/vm.c
in= dex a03e068..cf528e8 100644
--- a/vm.c
+++ b/vm.c
=40=40 -= 1400,6 +1400,9 =40=40 static void
rb=5Fvm=5Fcheck=5Fredefinition=5F= opt=5Fmethod(const rb=5Fmethod=5Fentry=5Ft *me, VALUE klass)
=7B st=5Fdata=5Ft bop;
+ if (RB=5FTYPE=5FP(klass, T=5FICLASS)= && =46L=5FTEST(klass, RICLASS=5FIS=5FORIGIN)) =7B
+ klass =3D RBASI= C=5FCLASS(klass);
+ =7D
if (me->def->type =3D=3D VM=5FM= ETHOD=5FTYPE=5FC=46UNC) =7B
if (st=5Flookup(vm=5Fopt=5Fmethod=5Fta= ble, (st=5Fdata=5Ft)me, &bop)) =7B
int flag =3D vm=5Fredefinit= ion=5Fcheck=5Fflag(klass);
=60=60=60


--------------= --------------------------
Bug =2311826: After prepending a module, = rewrite Hash=23=5B=5D takes no effect for calls like Hash.new=5B:a=5D
https://bugs.ruby-lang.org/issues/11826=23change-55609

* Aut= hor: cichol tsai
* Status: Assigned
* Priority: Normal
* A= ssignee: Koichi Sasada
* ruby -v: ruby 2.2.2p95 (2015-04-13 revision= 50295) =5Bx64-mingw32=5D
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN, = 2.2: UNKNOWN
----------------------------------------
=7E=7E=7E=
module M
def self.prepended(clz)
clz.class=5Feval d= o
def =5B=5D(k)
p 1
end
end end
end

module N
def self.included(clz)
clz.class=5Feval do
def =5B=5D=3D(k, v)
p 2=
end
end
end
end

class Hash prepend M
include N
end

Hash.new=5B1=5D
= Hash.new=5B1=5D=3D1
=7E=7E=7E

Running this example gives = no output, which is expected to be '1 2'.
I am using 'ruby 2.2.2p95 = (2015-04-13 revision 50295) =5Bx64-mingw32=5D'.
Thanks in advanced.<= br />


--
https://bugs.ruby-lang.org/
--5673866e_77ae35eb_16c--