diff --git a/src/metamodel/RoleHOW.pir b/src/metamodel/RoleHOW.pir index ec6ec1ad040..2fe475e0845 100644 --- a/src/metamodel/RoleHOW.pir +++ b/src/metamodel/RoleHOW.pir @@ -154,7 +154,24 @@ Add a method to the given meta. .param string name .param pmc meth $P0 = getattribute self, 'parrotclass' + push_eh add_fail addmethod $P0, name, meth + pop_eh + .return () + add_fail: + pop_eh + + # May be that we need to merge multis. + $P1 = $P0.'methods'() + $P1 = $P1[name] + $I0 = isa $P1, 'MultiSub' + unless $I0 goto error + $I0 = isa meth, 'MultiSub' + unless $I0 goto error + $P1.'incorporate_candidates'(meth) + .return () + error: + '&die'('Can not add two methods to a role if they are not multis') .end =item methods diff --git a/src/metamodel/RoleToRoleApplier.nqp b/src/metamodel/RoleToRoleApplier.nqp index be70bda35ea..4669be0e452 100644 --- a/src/metamodel/RoleToRoleApplier.nqp +++ b/src/metamodel/RoleToRoleApplier.nqp @@ -75,8 +75,19 @@ method apply($target, @composees) { $target.HOW.add_method($target, $name, @add_meths[0]); } else { - # More than one - add to collisions list. - $target.HOW.add_collision($target, $name); + # More than one - add to collisions list unless all multi. + my $num_multi := 0; + for @add_meths { + if $_.multi { $num_multi := $num_multi + 1; } + } + if +@add_meths == $num_multi { + for @add_meths { + $target.HOW.add_method($target, $name, $_); + } + } + else { + $target.HOW.add_collision($target, $name); + } } } }