[svn:parrot] r41810 - in branches/pcc_reapply: src/call t/op

tene at svn.parrot.org tene at svn.parrot.org
Sat Oct 10 23:09:01 UTC 2009


Author: tene
Date: Sat Oct 10 23:09:00 2009
New Revision: 41810
URL: https://trac.parrot.org/parrot/changeset/41810

Log:
[pcc] Fail correctly when positional args are passed to slurpy named params

Modified:
   branches/pcc_reapply/src/call/args.c
   branches/pcc_reapply/t/op/calling.t

Modified: branches/pcc_reapply/src/call/args.c
==============================================================================
--- branches/pcc_reapply/src/call/args.c	Sat Oct 10 22:13:08 2009	(r41809)
+++ branches/pcc_reapply/src/call/args.c	Sat Oct 10 23:09:00 2009	(r41810)
@@ -817,6 +817,7 @@
 {
     ASSERT_ARGS(fill_params)
     PMC    *named_used_list = PMCNULL;
+    PMC    *arg_sig;
     INTVAL  param_count     = VTABLE_elements(interp, raw_sig);
     INTVAL  positional_args;
     INTVAL  param_index     = 0;
@@ -841,6 +842,7 @@
     }
 
     positional_args = VTABLE_elements(interp, call_object);
+    arg_sig   = VTABLE_get_attr_str(interp, call_object, CONST_STRING(interp, "arg_flags"));
 
     /* First iterate over positional args and positional parameters. */
     arg_index = 0;
@@ -1020,6 +1022,18 @@
                     "named parameters must follow all positional parameters");
         }
 
+        if (arg_index < positional_args) {
+            /* We've used up all the positional parameters, but have extra
+             * positional args left over. */
+            if (VTABLE_get_integer_keyed_int(interp, arg_sig, arg_index) & PARROT_ARG_NAME) {
+                Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
+                        "named arguments must follow all positional arguments");
+            }
+            Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
+                    "too many positional arguments: %d passed, %d expected",
+                    positional_args, param_index);
+        }
+
         /* Collected ("slurpy") named parameter */
         if (param_flags & PARROT_ARG_SLURPY_ARRAY) {
             PMC * const collect_named = pmc_new(interp,

Modified: branches/pcc_reapply/t/op/calling.t
==============================================================================
--- branches/pcc_reapply/t/op/calling.t	Sat Oct 10 22:13:08 2009	(r41809)
+++ branches/pcc_reapply/t/op/calling.t	Sat Oct 10 23:09:00 2009	(r41810)
@@ -2287,7 +2287,7 @@
     .param pmc args :slurpy :named
 .end
 CODE
-/positional inside named args at position 2/
+/too many positional arguments/
 OUTPUT
 
 pir_error_output_like( <<'CODE', <<'OUTPUT', "unexpected positional arg" );
@@ -2300,7 +2300,7 @@
     .param pmc args :slurpy :named
 .end
 CODE
-/positional inside named args at position 3/
+/named arguments must follow all positional arguments/
 OUTPUT
 
 pir_output_is( <<'CODE', <<'OUTPUT', "RT #40490 - flat/slurpy named arguments" );


More information about the parrot-commits mailing list