Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[common] Implement searching for a proto in parent classes too, and i…

…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...
commit dc36346ac4a7ee60fbc1d44f435e8d003fe494de 1 parent 6e2fb41
@jnthn authored
Showing with 25 additions and 1 deletion.
  1. +25 −1 common/NQP/NQPSetting.pm
View
26 common/NQP/NQPSetting.pm
@@ -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;
}
Please sign in to comment.
Something went wrong with that request. Please try again.