Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stubbing a parent class breaks instantiating its child from within the parent definition #3423

Closed
p6rt opened this issue Jul 3, 2014 · 8 comments

Comments

@p6rt
Copy link

p6rt commented Jul 3, 2014

Migrated from rt.perl.org#122221 (status was 'rejected')

Searchable as RT122221$

@p6rt
Copy link
Author

p6rt commented Oct 15, 2012

From @masak

<masak> r​: class A { ... }; class B is A {}; class A {}; say B.new; say "alive"
<p6eval> rakudo 8a07b8​: OUTPUT«No such method 'new' for invocant of
type 'B'␤ in block [...]
* masak submits rakudobug
<masak> r​: class A { ... }; class B is A {}; class A { has B $.bar };
say A.new.bar
<p6eval> rakudo 8a07b8​: OUTPUT«No such method 'gist' for invocant of
type 'B'␤ in sub say [...]

Found by diakopter++.

@p6rt
Copy link
Author

p6rt commented Oct 15, 2012

From @masak

<moritz> I don't think you should be able to inherit from a class that's
only stubbed
<moritz> the proper way is to stub the subclass
<masak> I agree that the problem we're seeing here stems from deriving
from the stubbed class.
<masak> I'm not yet convinced it shouldn't be allowed.
<masak> oh, TimToady++ has a fix in the backlog​:
<masak> r​: class A is Any { ... }; class B is A { has A $.foo }; class A
{ has B $.bar }; say A.new.bar
<p6eval> rakudo 8a07b8​: OUTPUT«B()␤»
* masak includes this in the ticket

@p6rt
Copy link
Author

p6rt commented Oct 15, 2012

@masak - Status changed from 'new' to 'open'

@p6rt
Copy link
Author

p6rt commented Jul 3, 2014

From pjablons@conncoll.edu

23​:29 psch m​: class A​::B {...}; class A​::C is A​::B { method WHICH { say "which" } }; class A​::B { method inst { return A​::C.new } }; my $a = A​::B.inst; $a.WHICH
23​:29 camelia rakudo-moar b8a188​: OUTPUT«Cannot invoke this object (REPR​: Null, cs = 0)␤ in method inst at /tmp/tOJLKN8zrC​:1␤ in block at /tmp/tOJLKN8zrC​:1␤␤»
23​:29 psch that's it
23​:30 the WHICH is actually also not doing anything there
23​:30 r​: class A​::B {...}; class A​::C is A​::B { }; class A​::B { method inst { return A​::C.new } }; my $a = A​::B.inst; $a.WHICH
23​:30 camelia rakudo-jvm b8a188​: OUTPUT«(timeout)»
23​:30 ..rakudo-parrot b8a188​: OUTPUT«No such method 'new' for invocant of type 'A​::C'␤ in method inst at /tmp/tmpfile​:1␤ in block at /tmp/tmpfile​:1␤␤»
23​:30 ..rakudo-moar b8a188​: OUTPUT«Cannot invoke this object (REPR​: Null, cs = 0)␤ in method inst at /tmp/tmpfile​:1␤ in block at /tmp/tmpfile​:1␤␤»
23​:31 BenGoldberg std​: class A​::B {...}; class A​::C is A​::B { }; class A​::B { method inst { return A​::C.new } }; my $a = A​::B.inst; $a.WHICH
23​:31 camelia std 0f2049c​: OUTPUT«ok 00​:01 126m␤»
23​:31 BenGoldberg n​: class A​::B {...}; class A​::C is A​::B { }; class A​::B { method inst { return A​::C.new } }; my $a = A​::B.inst; $a.WHICH
23​:31 camelia niecza v24-109-g48a8de3​: OUTPUT«[31m===[0mSORRY![31m===[0mâ�¤â�¤Two definitions found for symbol :​:GLOBAL​::A​::Bâ�¤â�¤ first at /tmp/2EXdgwIiRt line 1â�¤ second at /tmp/2EXdgwIiRt line 1 at /tmp/2EXdgwIiRt line 1​:â�¤------> [32m..}; class A​::C is A​::B { }; class A​::B [33mâ��…»
23​:32 psch so what happens there? .new doesn't end up in A​::B for some reason?
23​:34 ren1us​: i'm rather sure by now that it's a bug; .new from Mu should definitely end up in A​::B and also in A​::C, but even if you write it yourself self somehow breaks...
23​:35 unless i'm lacking some knowledge wrt how OO works in Perl 6, which is definitely not impossible...
23​:36 ren1us is it just that it's not being inherited down after a certain number of levels, or is it getting tripped by something weirder you think?
23​:37 psch m​: class A​::B { method inst { return A​::C.new } }; class A​::C is A​::B { }; my $a = A​::B.inst;
23​:37 camelia rakudo-moar f8a933​: OUTPUT«Could not find symbol '&C'␤ in method <anon> at src/gen/m-CORE.setting​:12879␤ in any find_method_fallback at src/gen/m-Metamodel.nqp​:2604␤ in any find_method at src/gen/m-Metamodel.nqp​:934␤ in method inst at /tmp/U7fAWu3RnR​:1␤ in block at /…»
23​:38 psch ren1us​: i'm not sure i know at all what's going on :)
23​:38 ren1us well shit
23​:38 psch m​: class B { method inst { return C.new } }; class C is B { }; my $a = B.inst;
23​:38 camelia rakudo-moar f8a933​: OUTPUT«[31m===[0mSORRY![31m===[0m Error while compiling /tmp/lnK_v0DET6â�¤Illegally post-declared type​:â�¤ C used at line 1â�¤â�¤Â»
23​:38 ren1us i feel like the stubbing has something to do with it
23​:38 just a hunch
23​:38 psch m​: class C { }; class B { method inst { return C.new } }; class C is B { }; my $a = B.inst;
23​:38 camelia rakudo-moar f8a933​: OUTPUT«[31m===[0mSORRY![31m===[0m Error while compiling /tmp/KCuw_5Tfexâ�¤Redeclaration of symbol Câ�¤at /tmp/KCuw_5Tfex​:1â�¤------> [32md inst { return C.new } }; class C is B [33mâ��[31m{ }; my $a = B.inst;[0mâ�¤ expecting any of​:â�¤ method ar…»
23​:39 psch m​: class C { ... }; class B { method inst { return C.new } }; class C is B { }; my $a = B.inst;
23​:39 camelia rakudo-moar f8a933​: ( no output )
23​:39 Khisanth joined #perl6
23​:39 psch ren1us​: i guess you have to shuffle your code around a bit
23​:39 apparently stubbing the class that gets instantiated works

@p6rt
Copy link
Author

p6rt commented Jul 3, 2014

From @moritz

On 03.07.2014 13​:04, Peter (via RT) wrote​:

# New Ticket Created by Peter
# Please include the string​: [perl #​122221]
# in the subject line of all future correspondence about this issue.
# <URL​: https://rt-archive.perl.org/perl6/Ticket/Display.html?id=122221 >

23​:29 psch m​: class A​::B {...}; class A​::C is A​::B { method WHICH { say "which" } }; class A​::B { method inst { return A​::C.new } }; my $a = A​::B.inst; $a.WHICH
23​:29 camelia rakudo-moar b8a188​: OUTPUT«Cannot invoke this object (REPR​: Null, cs = 0)␤ in method inst at /tmp/tOJLKN8zrC​:1␤ in block at /tmp/tOJLKN8zrC​:1␤␤»

I don't see how that could ever be made to work. At the time that the
child classes' closing bracket is parsed, the class is composed, which
mean its method table (including methods from superclasses) is calculated.

This means at the very least that if you inherit from a stubbed class,
you won't be able to call methods from the parent class.

So the best thing we can do is throw a better error message, at class
inheritance time.

Cheers,
Moritz

@p6rt
Copy link
Author

p6rt commented Jul 3, 2014

The RT System itself - Status changed from 'new' to 'open'

@p6rt
Copy link
Author

p6rt commented Feb 10, 2015

From @usev6

Rakudo now dies with a typed exception X​::Inheritance​::NotComposed when trying to inherit from a stubbed class -- cmp. ticket 81060 (https://rt-archive.perl.org/perl6/Ticket/Display.html?id=81060). I don't merge both tickets since that would make things rather confusing IMHO.

On the basis of Moritz's comment and the implemented typed exception, I'm rejecting this ticket. If you don't agree, please reopen.

@p6rt
Copy link
Author

p6rt commented Feb 10, 2015

@usev6 - Status changed from 'open' to 'rejected'

@p6rt p6rt closed this as completed Feb 10, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant