Skip to content

Instantly share code, notes, and snippets.

@masak
Created July 4, 2010 18:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save masak/463655 to your computer and use it in GitHub Desktop.
Save masak/463655 to your computer and use it in GitHub Desktop.
class A { method foo($x, $y) { say "A"; nextsame } }
class B is A { multi method foo($x, $y) { say "B"; nextsame } }
class C is B { multi method foo($x, $y) { say "C"; nextsame } }
C.new.foo("OH", "HAI");
# masak thinks this should print "C\nB\nA\n", because that's what it looks
# like it should produce, and anything other than that breaks Least Surprise.
# jnthn thinks there's no way it can't print anything other than
# "C\nB\nB\nA\n", because of the two-level dispatcher layering (one layer
# for C3 dispatch, and another for "these multies go together" dispatch.
# Because these are independent, and because B.foo and C.foo "go together"
# due to both being multies, B gets called a second time when the inner
# dispatcher runs out of candidates, and the outer one proceeds up from
# A to B.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment