diff --git a/src/compiler/parse_global.c b/src/compiler/parse_global.c index 31db08bd0..0dec7d2c5 100644 --- a/src/compiler/parse_global.c +++ b/src/compiler/parse_global.c @@ -1656,6 +1656,10 @@ bool parse_parameters(ParseContext *c, Decl ***params_ref, Variadic *variadic, i print_error_after(c->prev_span, "Expected a parameter."); return false; } + if (parse_kind == PARAM_PARSE_MACRO && ellipsis && type) + { + print_error_after(c->prev_span, "A typed macro vaarg must have a parameter name."); + } no_name = true; span = c->prev_span; param_kind = VARDECL_PARAM; diff --git a/src/compiler/sema_expr.c b/src/compiler/sema_expr.c index 70db49119..d6c0e2989 100644 --- a/src/compiler/sema_expr.c +++ b/src/compiler/sema_expr.c @@ -2681,7 +2681,7 @@ static inline bool sema_expr_setup_call_analysis(SemaContext *context, CalledDec expr->expr_other_context.inner = expr_inner; expr->expr_other_context.context = context; } - macro_context->macro_varargs = callee->macro ? call_expr->call_expr.varargs : NULL; + macro_context->macro_varargs = callee->macro && callee->signature->variadic == VARIADIC_RAW ? call_expr->call_expr.varargs : NULL; macro_context->original_inline_line = context->original_inline_line ? context->original_inline_line : call_expr->span.row; macro_context->original_module = context->original_module ? context->original_module : context->compilation_unit->module; macro_context->macro_params = params; diff --git a/test/test_suite/functions/vaarg_no_name_macro.c3 b/test/test_suite/functions/vaarg_no_name_macro.c3 new file mode 100644 index 000000000..bab21f658 --- /dev/null +++ b/test/test_suite/functions/vaarg_no_name_macro.c3 @@ -0,0 +1,16 @@ +module test; +import std; +fn int main(String[] args) +{ + test2(test1(1)); + return 0; +} + +macro String test1(a) => "abc"; + +macro test2(String...) // #error: must have a parameter name +{ + $for var $i = 0; $i < $vacount; $i++: + io::printfn($vaarg[$i]); + $endfor +}