Skip to content

Commit

Permalink
[common] Implement searching for a proto in parent classes too, and i…
Browse files Browse the repository at this point in the history
…nstantiating it anew in the child class that is doing candidate incorporation. Won't yet handle re-composition and new candidates added beyond composition, but that's evil anyway, so no hurry there. :-)
  • Loading branch information
jnthn committed Oct 31, 2010
1 parent 6e2fb41 commit dc36346
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion common/NQP/NQPSetting.pm
Expand Up @@ -428,7 +428,31 @@ knowhow NQPClassHOW {
}
}
else {
die("Can't yet instantiate proto from a parent class.");
# Go hunting in the MRO for a proto.
my $j := 1;
my $found := 0;
while $j != +@!mro && !$found {
my $parent := @!mro[$j];
my %meths := $parent.HOW.method_table($parent);
my $dispatcher := %meths{$name};
if $dispatcher.defined {
# Found a possible - make sure it's a dispatcher, not
# an only.
if nqp::is_dispatcher($dispatcher) {
# Clone it and install it in our method table.
my @new_dispatchees;
@new_dispatchees[0] := $code;
%!methods{$name} := nqp::create_dispatch_and_add_candidates($dispatcher, @new_dispatchees);
$found := 1;
}
else {
die("Could not find a proto for multi $name (it may exist, but an only is hiding it if so)");
}
}
}
unless $found {
die("Could not find a proto for multi $name, and proto generation is NYI");
}
}
$i := $i + 1;
}
Expand Down

0 comments on commit dc36346

Please sign in to comment.