Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[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
Jonathan Worthington authored October 31, 2010

Showing 1 changed file with 25 additions and 1 deletion. Show diff stats Hide diff stats

  1. 26  common/NQP/NQPSetting.pm
26  common/NQP/NQPSetting.pm
@@ -428,7 +428,31 @@ knowhow NQPClassHOW {
428 428
                 }
429 429
             }
430 430
             else {
431  
-                die("Can't yet instantiate proto from a parent class.");
  431
+                # Go hunting in the MRO for a proto.
  432
+                my $j := 1;
  433
+                my $found := 0;
  434
+                while $j != +@!mro && !$found {
  435
+                    my $parent := @!mro[$j];
  436
+                    my %meths := $parent.HOW.method_table($parent);
  437
+                    my $dispatcher := %meths{$name};
  438
+                    if $dispatcher.defined {
  439
+                        # Found a possible - make sure it's a dispatcher, not
  440
+                        # an only.
  441
+                        if nqp::is_dispatcher($dispatcher) {
  442
+                            # Clone it and install it in our method table.
  443
+                            my @new_dispatchees;
  444
+                            @new_dispatchees[0] := $code;
  445
+                            %!methods{$name} := nqp::create_dispatch_and_add_candidates($dispatcher, @new_dispatchees);
  446
+                            $found := 1;
  447
+                        }
  448
+                        else {
  449
+                            die("Could not find a proto for multi $name (it may exist, but an only is hiding it if so)");
  450
+                        }
  451
+                    }
  452
+                }
  453
+                unless $found {
  454
+                    die("Could not find a proto for multi $name, and proto generation is NYI");
  455
+                }
432 456
             }
433 457
             $i := $i + 1;
434 458
         }

0 notes on commit dc36346

Please sign in to comment.
Something went wrong with that request. Please try again.