harec

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit 12547d0f9e0288be03f1c8a6b9c9980622bbec56
parent 8a473414daff938cfcbead5d1401de8a04aa9a87
Author: Drew DeVault <sir@cmpwn.com>
Date:   Mon,  1 Feb 2021 19:00:17 -0500

check: fix variadic calls with no params

Diffstat:
Msrc/check.c | 14+++++++++++++-
Mtests/09-funcs.ha | 1+
2 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/src/check.c b/src/check.c @@ -483,11 +483,14 @@ lower_vaargs(struct context *ctx, { struct ast_expression val = { .type = EXPR_CONSTANT, - .loc = aarg->value->loc, .constant = { .storage = TYPE_STORAGE_ARRAY, }, }; + // TODO: Provide location some other way + if (aarg) { + val.loc = aarg->value->loc; + } struct ast_array_constant **next = &val.constant.array; while (aarg) { struct ast_array_constant *item = *next = @@ -569,6 +572,15 @@ check_expr_call(struct context *ctx, trleave(TR_CHECK, NULL); } + if (param && fntype->func.variadism == VARIADISM_HARE) { + // No variadic arguments, lower to empty slice + arg = *next = xcalloc(1, sizeof(struct call_argument)); + arg->value = xcalloc(1, sizeof(struct expression)); + lower_vaargs(ctx, NULL, arg->value, param->type->array.members); + arg->value = lower_implicit_cast(param->type, arg->value); + param = param->next; + } + expect(&aexpr->loc, !aarg, "Too many parameters for function call"); expect(&aexpr->loc, !param, "Not enough parameters for function call"); diff --git a/tests/09-funcs.ha b/tests/09-funcs.ha @@ -29,6 +29,7 @@ fn vaargs() void = { vafn([1, 2, 3], 1, 2, 3); let data = [1, 2, 3]; vafn(data, data...); + vafn([]); }; let x: int = 42;