develooper Front page | perl.perl6.compiler | Postings from September 2011

[perl #100124] [BUG] Roles composed through two different paths and also containing an attribute with a default triggers a bogus error in Rakduo

From:
Carl Mäsak
Date:
September 27, 2011 03:29
Subject:
[perl #100124] [BUG] Roles composed through two different paths and also containing an attribute with a default triggers a bogus error in Rakduo
Message ID:
rt-3.6.HEAD-31297-1317119364-256.100124-82-0@perl.org
# New Ticket Created by  "Carl Mäsak" 
# Please include the string:  [perl #100124]
# in the subject line of all future correspondence about this issue. 
# <URL: https://rt.perl.org:443/rt3/Ticket/Display.html?id=100124 >


<masak> ok, here we go.
<masak> nom: my $x; role A { has $!foo }; role B does A {}; role C
does A {}; class D does B does C {}; say "alive"
<p6eval> nom 41eceb: OUTPUT«alive␤»
<masak> nom: my $x; role A { has $!foo = $x }; role B does A {}; role
C does A {}; class D does B does C {}
<p6eval> nom 41eceb: OUTPUT«===SORRY!===␤Attribute '$!foo' conflicts
in role composition␤»
<masak> b: my $x; role A { has $!foo = $x }; role B does A {}; role C
does A {}; class D does B does C {}; say "alive"
<p6eval> b 1b7dd1: OUTPUT«alive␤»
* masak submits rakudobug
<masak> note, that external reference to $x is *necessary* to trigger
the role composition error.
<jnthn> Ah, that kinda follows.
<masak> it does?
<masak> I'm glad it's obvious to one of us :P
<jnthn> masak: Attributes that have defaults always get their
meta-objects generically instantiated.
<jnthn> masak: Because the default may refer to role arguments.
<masak> oh!
<jnthn> masak: I suspect we're doing an identity check in the role composer.
<masak> nom: my $x; role A { has $!foo = 42 }; role B does A {}; role
C does A {}; class D does B does C {}; say "alive"
<p6eval> nom 41eceb: OUTPUT«===SORRY!===␤Attribute '$!foo' conflicts
in role composition␤»
<jnthn> masak: And instead it wants to check name + declaring package.
<masak> ok, so this is a bug? phew!
<jnthn> Yeah, it should be fixed.
* masak beams
<jnthn> Just thought an explanation of why the default value matters
might be interesting. ;)
<masak> was a long time I found a bug as juicy as this :)
<jnthn> It's subtle, yes.

So: define role with attribute with a default. Compose it twice
(legitimately) into a class. Boom.



nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About