On Sat Jul 15 23:29:10 2006, mdiep wrote:
> I expect this to die with a "too many args" error, but it doesn't --  
> it prints "ok":
> 
>    .sub main :main
>      test("foo", "bar")
>      end
>    .end
> 
>    .sub test
>      print "ok\n"
>      .return()
>    .end
> 
> --
> Matt Diephouse
> 

Here's a simple patch that implements this:

$ svn diff compilers/
Index: compilers/imcc/pcc.c
=========================================================
==========
--- compilers/imcc/pcc.c        (revision 27756)
+++ compilers/imcc/pcc.c        (working copy)
@@ -319,16 +319,10 @@
         unshift_self(sub, self);
     }

-    /* Don't generate any parameter checking code if there
-     * are no named arguments.
-     */
     nargs = sub->pcc_sub->nargs;
+    ins = pcc_get_args(interp, unit, ins, "get_params", nargs,
+        sub->pcc_sub->args, sub->pcc_sub->arg_flags);

-    if (nargs) {
-        ins = pcc_get_args(interp, unit, ins, "get_params", nargs,
-                sub->pcc_sub->args, sub->pcc_sub->arg_flags);
-    }
-
     /*
      * check if there is a return
      */

The problem with this is that it also applies to subs marked :main, and I don't 
think we wish 
to enforce it for :main - the args passed in may not match at all. If someone 
can tweak this 
slightly to avoid inserting the get_params opcode in that one case, that should 
be sufficient 
to close out this case. Added a test case to t/op/calling.t; Thanks to mdiep 
for the pointer to 
the fix. (I had been staring at src/inter_call.c for some time to no avail)



Reply via email to