[perl #54520] [BUG] superclass methods of PMC classes aren't inherited
Andrew Whitworth via RT
parrotbug-followup at parrotcode.org
Fri Feb 6 15:40:05 UTC 2009
On Wed May 21 06:05:30 2008, vany wrote:
> There is more complex description of this problem:
> Subclassing is broken when a parentclas has an instances:
>
> .sub main :main
> .local pmc ca,cb,cc,oa,oa1
> ca=newclass 'A'
> cb=newclass 'B'
> cc=newclass 'C'
> ca=addparent cb
> # oa1=new 'A'
> cb=addparent cc
> oa=new 'A'
> oa.'doit'()
> .end
>
>
> .namespace ['C']
> .sub doit :method
> say 'LALALA!'
> .end
>
>
> This code works well until we uncomment oa1=new 'A'
>
> There is a question:
> How it must work ?
> I can fix this, but i want remove the dependness of created objects.
>
Okay, I found the problem here through a little bit of experimentation.
When a class instantiated, it's MRO is fixed. So when you instantiate
object oa1, you're fixing the MRO of class 'A'. After you've done that,
you change the class hierarchy by adding B as a subclass as C. This
means that by creating the first 'A', you're saying that the class MRO
can no longer be modified because you already have an object of that
class created, and then you cannot add 'doit'() to the MRO by adding C
as a parent class of B.
This code works perfectly:
.sub main :main
.local pmc ca, cb, cc, oa
cc = newclass 'C'
cb = subclass cc, 'B' # Could also use newclass/addparent like the
example
ca = subclass cb, 'A'
oa = new 'A'
oa.'doit'()
.end
The question is this: Do we want this behavior to change? Do we want to
be able to change the MRO of a class after that class has been
instantiated? This would require at least a handful of additional checks
at runtime to verify that the class hierarchy has not changed in any
appreciable way.
If we want this, it will be easy enough to add (although initial
implementation will likely be less efficient then people would like). If
we don't, this ticket gets rejected as wontfix. Any feedback?
--
Andrew Whitworth
a.k.a Whiteknight
More information about the parrot-dev
mailing list