Skip to content

Commit

Permalink
More fixing of multis composed from multiple roles.
Browse files Browse the repository at this point in the history
  • Loading branch information
jnthn committed May 2, 2010
1 parent b2476f7 commit 72ef184
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
17 changes: 17 additions & 0 deletions src/metamodel/RoleHOW.pir
Expand Up @@ -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
Expand Down
15 changes: 13 additions & 2 deletions src/metamodel/RoleToRoleApplier.nqp
Expand Up @@ -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);
}
}
}
}
Expand Down

0 comments on commit 72ef184

Please sign in to comment.