From 4b028dc6e17b84f7bf952228c120396f194dd325 Mon Sep 17 00:00:00 2001 From: rgrjr Date: Sat, 14 Jul 2007 15:17:23 +0000 Subject: [PATCH] * src/mmd.c: + (mmd_arg_tuple_func): Move the :flat code into the type select, and don't return directly when done, because there might be more args afterwards. Fix for RT#43869. * t/pmc/multisub.t: + Add a :flat case and a "double :flat" case. git-svn-id: https://svn.perl.org/parrot/trunk@19860 d31e2699-5ff4-0310-a27c-f18f2fbe73fe --- src/mmd.c | 30 +++++++++++++++--------------- t/pmc/multisub.t | 27 ++++++++++++++++++++++++++- 2 files changed, 41 insertions(+), 16 deletions(-) diff --git a/src/mmd.c b/src/mmd.c index b3e16c7437..9e99f1ac44 100644 --- a/src/mmd.c +++ b/src/mmd.c @@ -1024,21 +1024,7 @@ mmd_arg_tuple_func(PARROT_INTERP) /* named don't MMD */ if (type & PARROT_ARG_NAME) break; - /* expand flattening args */ - if (type & PARROT_ARG_FLATTEN) { - int j, n; - - idx = *args_op; - arg = REG_PMC(interp, idx); - n = VTABLE_elements(interp, arg); - for (j = 0; j < n; ++j) { - PMC * const elem = VTABLE_get_pmc_keyed_int(interp, arg, j); - type = VTABLE_type(interp, elem); - VTABLE_push_integer(interp, arg_tuple, type); - } - return arg_tuple; - } - switch (type & PARROT_ARG_TYPE_MASK) { + switch (type & (PARROT_ARG_TYPE_MASK | PARROT_ARG_FLATTEN)) { case PARROT_ARG_INTVAL: VTABLE_push_integer(interp, arg_tuple, enum_type_INTVAL); break; @@ -1057,6 +1043,20 @@ mmd_arg_tuple_func(PARROT_INTERP) type = VTABLE_type(interp, arg); VTABLE_push_integer(interp, arg_tuple, type); break; + case PARROT_ARG_FLATTEN | PARROT_ARG_PMC: { + /* expand flattening args */ + int j, n; + + idx = *args_op; + arg = REG_PMC(interp, idx); + n = VTABLE_elements(interp, arg); + for (j = 0; j < n; ++j) { + PMC * const elem = VTABLE_get_pmc_keyed_int(interp, arg, j); + type = VTABLE_type(interp, elem); + VTABLE_push_integer(interp, arg_tuple, type); + } + break; + } default: real_exception(interp, NULL, 1, "Unknown signature type %d in mmd_arg_tuple", type); diff --git a/t/pmc/multisub.t b/t/pmc/multisub.t index ff237b5cbb..32886e501a 100644 --- a/t/pmc/multisub.t +++ b/t/pmc/multisub.t @@ -26,7 +26,7 @@ Tests the creation and invocation of Perl6 multi subs. exports = split " ", "plan ok is" test_namespace.export_to(curr_namespace, exports) - plan( 6 ) + plan( 8 ) $P0 = new .MultiSub $I0 = defined $P0 @@ -44,6 +44,20 @@ Tests the creation and invocation of Perl6 multi subs. $S0 = foo(42, "goodbye") is($S0, "testing 42, goodbye", "int and string variant") + ## Test handling of :flat parameters. + $P0 = new .ResizablePMCArray + push $P0, 42 + push $P0, "goodbye" + $S0 = foo($P0 :flat) + is($S0, "testing 42, goodbye", "Int and String :flat") + ## Now try double :flat (regression test for RT#43869). + $P1 = new .ResizablePMCArray + push $P1, 42 + $P2 = new .ResizablePMCArray + push $P2, "goodbye" + $S0 = foo($P1 :flat, $P2 :flat) + is($S0, "testing 42, goodbye", "Int and String double :flat") + .end .sub foo :multi() @@ -73,6 +87,17 @@ Tests the creation and invocation of Perl6 multi subs. .return ($S0) .end +.sub foo :multi(Integer, String) + .param pmc bar + .param pmc baz + $S1 = bar + $S2 = baz + $S0 = "testing " . $S1 + $S0 .= ", " + $S0 .= $S2 + .return ($S0) +.end + # Local Variables: # mode: pir # fill-column: 70 -- 2.11.4.GIT