diff --git a/src/Perl6/Actions.pm b/src/Perl6/Actions.pm index 4365633fb2c..f8b0e0851a4 100644 --- a/src/Perl6/Actions.pm +++ b/src/Perl6/Actions.pm @@ -978,7 +978,11 @@ method routine_def($/) { PAST::Op.new( :inline(' %r = new ["Perl6MultiSub"]') ), $past ); - $symbol_holder.symbol($name, :multis($past)) + $symbol_holder.symbol($name, :multis($past)); + $past := PAST::Op.new( + :pasttype('callmethod'), :name('incorporate_candidates'), + $past, PAST::Op.new( :pirop('find_lex_skip_current PS'), $name ) + ); } $multi_flag.value($*MULTINESS eq 'proto' ?? 2 !! 1); } diff --git a/src/pmc/perl6multisub.pmc b/src/pmc/perl6multisub.pmc index b325e3dd87d..c8c53f50532 100644 --- a/src/pmc/perl6multisub.pmc +++ b/src/pmc/perl6multisub.pmc @@ -1312,6 +1312,26 @@ that we may have in place. Returns SELF. } RETURN (PMC *SELF); } + + +/* + +=item METHOD PMC *incorporate_candidates(PMC *maybe_multi) + +Incorporates the given candidates into this multi. + +=cut + +*/ + METHOD PMC *incorporate_candidates(PMC *maybe_multi) { + if (!PMC_IS_NULL(maybe_multi) && VTABLE_isa(interp, maybe_multi, CONST_STRING(interp, "Perl6MultiSub"))) { + INTVAL elements = VTABLE_elements(interp, maybe_multi); + INTVAL i; + for (i = 0; i < elements; i++) + VTABLE_push_pmc(interp, SELF, VTABLE_get_pmc_keyed_int(interp, maybe_multi, i)); + } + RETURN (PMC *SELF); + } } /*