diff options
-rw-r--r-- | test.toc | 4 | ||||
-rw-r--r-- | types.c | 15 |
2 files changed, 14 insertions, 5 deletions
@@ -1,6 +1,6 @@ #include "std/io.toc"; -g ::= fn(modulator:: int, x : ..) int { +g ::= fn(modulator:: int, x :: ..) int { total := 0; for e := x { total += modulator * (e as int); @@ -8,7 +8,7 @@ g ::= fn(modulator:: int, x : ..) int { total }; -f ::= fn(x : ..) int { +f ::= fn(x :: ..) int { g(2, x) }; @@ -2191,15 +2191,24 @@ static Status types_expr(Typer *tr, Expression *e) { VarArg *varargs = NULL; arr_set_lena(&varargs, nvarargs, tr->allocr); Declaration *varargs_param = arr_last(fn_copy->params); + DeclFlags is_const = varargs_param->flags & DECL_IS_CONST; varargs_param->val.varargs = varargs; for (int v = 0; v < (int)nvarargs; ++v) { Expression *arg = &arg_exprs[v+order[nparams-1]]; VarArg *vararg = &varargs[v]; - - if (varargs_param->flags & DECL_IS_CONST) - vararg->val = arg->val; + if (is_const) { + Value val; + if (!eval_expr(tr->evalr, arg, &val)) + return false; + arg->kind = EXPR_VAL; + arg->val = val; + copy_val(tr->allocr, &vararg->val, arg->val, &arg->type); + } vararg->type = &arg->type; } + if (is_const) { + varargs_param->flags |= DECL_FOUND_VAL; + } } } |