Skip Menu |
Report information
Id: 130634
Status: open
Priority: 0/
Queue: perl6

Owner: Nobody
Requestors: comdog <brian.d.foy [at]>

Severity: (no value)
Tag: (no value)
Platform: (no value)
Patch Status: (no value)
VM: (no value)

From: brian d foy <brian.d.foy [...]>
Date: Tue, 24 Jan 2017 10:30:59 -0500
To: rakudobug [...]
Subject: Should Perl 6 be able to untangle the inclusion of the same role from different sources?
Download (untitled) / with headers
text/plain 2.1k
I posted this to Stackoverflow without anyone pointing out the error of my ways, so I think this is probably a bug. Imagine a series of complex grammars represented as roles, although this simple example is enough to show the conflict: role Alpha { token alpha { :i <[A..Z]> } } role Digit { token digit { <[0..9]> } } role Either does Alpha does Digit { token either { <alpha> | <digit> } } grammar Thingy does Either does Alpha { token TOP { <alpha> <either>* } } my $match = Thingy.parse( '1a3' ); dd $match; This doesn't work because Perl 6 doesn't untangle the relationships to figure out that the conflict is actually the same thing from the same source: Method 'alpha' must be resolved by class Thingy because it exists in multiple roles But, reading [S14](, I see: A role may not inherit from a class, but may be composed of other roles. However, this "crony" composition is not evaluated until class composition time. This means that if two roles bring in the same crony, there's no conflict--it's just as if the class pulled in the crony role itself and the respective roles didn't. A role may never conflict with itself regardless of its method of incorporation. I read that to mean that the roles are applied as late as possible, so the class `Thingy` would be able to disentangle that `Alpha` is included in two different parts. I figured this would work something like creating a list of all of the roles that would make up the final class, then applying that list only to the final class. That way, something like `Either` would mix-in only the things it defined and would rely on the later composition to bring in `Alpha`. I ran across this when I was trying to implement grammars for various (IETF) RFCs. Many of them reference the grammars from other RFCs, which makes it impossible for Perl 6 to resolve inheritance by C3. So, I figured that roles would disconnect the relationships. Apparently it doesn't.
Subject: [perl #130634]
Date: Tue, 24 Jan 2017 20:10:39 -0500
To: rakudobug [...]
From: raiph mellor <raiph.mellor [...]>
Download (untitled) / with headers
text/plain 490b
Download (untitled) / with headers
text/html 1023b
Golf'd to:

role A { method m {} }
role B does A {}
class C does A does B {}

Method 'm' must be resolved by class C because it exists in multiple roles (A, B)

Note that the same issue leads also to:

role A { has $a }
role B does A {}
class C does A does B {}

Attribute '$!a' conflicts in role composition

A number of devs discussed this on #perl6 with the useful part starting here:

and ending with jnthn's thoughts.


This service is sponsored and maintained by Best Practical Solutions and runs on infrastructure.

For issues related to this RT instance (aka "perlbug"), please contact perlbug-admin at