Hello,

I'm working on a fix for https://github.com/rakudo/rakudo/issues/2250. While 
the problem itself is easily tracks down to add_method not reporting a error, 
the general fix requires clear understanding of what happens to submethods when 
a role consumes another role. While things are pretty straightforward for 
methods, which are copied over from the source role to the target, for 
submethods not everything is so clear as I see it. Let's consider the following 
setup:

role R1 { submethod foo { "R1::foo" } }
role R2 does R1 { }
class Foo does R2 { submethod foo { "Foo::foo" } }

Imagine a code which would like to execute all submethods of all classes and 
roles. Normally, it would traverse mro and all role concretizations of each 
class from mro. In the example above such code would call submethod foo() from 
R1 twice: for R2 and R1 itself! Of course, there is a workaround for this as 
foo from R1 will have its .package set to R1. But what sense does such copying 
makes? When a role gets applied to class it does make some sense when we talk 
about BUILD/TWEAK/DESTROY. Though if 
https://github.com/rakudo/rakudo/issues/2241 gets implemented then even this 
use case will be obsoleted.

So, to have a comprehensive fix for #2250 I need to know how to handle 
submethods when a role is applied to a role: either I leave them untouched 
where they're (and this would be my choice); or I get them copied alongside 
with methods.

Best regards,
Vadim Belman

Reply via email to