diff --git a/lib/run.c b/lib/run.c index 97f62ba6..c6ded36b 100644 --- a/lib/run.c +++ b/lib/run.c @@ -6011,7 +6011,7 @@ static hawk_val_t* eval_binop_mod (hawk_rtx_t* rtx, hawk_val_t* left, hawk_val_t switch (n3) { case 0: - if (l2 == 0) + if (l2 == 0) { hawk_rtx_seterrnum (rtx, HAWK_NULL, HAWK_EDIVBY0); return HAWK_NULL; @@ -6793,9 +6793,11 @@ hawk_val_t* hawk_rtx_evalcall ( /* make a new stack frame */ stack_req = 4 + call->nargs; - if (fun) + if (fun && fun->nargs > call->nargs) { - HAWK_ASSERT (fun->nargs >= call->nargs); /* the compiler must guarantee this */ + /* for variadic functions, fun->nargs can be less than call->nargs. + * for non-variadic functions, the compiler must guarantee that fun->nargs >= call->nargs + * this case can happen for for non-variadic functions only. */ stack_req += fun->nargs - call->nargs; } /* if fun is HAWK_NULL, there is no way for this function to know expected argument numbers. @@ -7153,25 +7155,11 @@ static hawk_oow_t push_arg_from_nde (hawk_rtx_t* rtx, hawk_nde_fncall_t* call, v break; } - case 'V': - /* the variadic argument marked with ... in the function parameter */ - if (p->type == HAWK_NDE_LCL) - { - hawk_nde_var_t* var = (hawk_nde_var_t*)p; - v = hawk_rtx_makeintval(rtx, ((hawk_nde_var_t*)p)->id.idxa); - } - else - { - /* THIS IS THE RUNTIME ERROR */ - /* TODO: */ - } - case 'x': /* a regular expression is passed to the function as it is */ v = eval_expression0(rtx, p); break; - default: normal_arg: v = eval_expression(rtx, p); diff --git a/t/h-002.hawk b/t/h-002.hawk index 8011f79b..c7e70a59 100644 --- a/t/h-002.hawk +++ b/t/h-002.hawk @@ -585,7 +585,7 @@ function main() { - @local a, b; + @local a, b, f; RSTART=99; RLENGTH=99; @@ -652,6 +652,12 @@ function main() tap_ensure (test10(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), 55, @SCRIPTNAME, @SCRIPTLINE); tap_ensure (test11("aa", "bb", "cc"), 0, @SCRIPTNAME, @SCRIPTLINE); tap_ensure (test11("aa", "bb", "cc", "dd"), 1, @SCRIPTNAME, @SCRIPTLINE); + + f = test11; + tap_ensure (f("aa", "bb", "cc", "dd"), 1, @SCRIPTNAME, @SCRIPTLINE); + + f = test10 + tap_ensure (f(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), 55, @SCRIPTNAME, @SCRIPTLINE); } tap_end (); }