From 90f0486334f1e79c5cf518c23b6b98cf53556e2b Mon Sep 17 00:00:00 2001 From: Christoffer Lerno Date: Tue, 30 Dec 2025 12:28:03 +0100 Subject: [PATCH] - Assert when encountering a test function with raw vaarg parameters. --- releasenotes.md | 1 + src/compiler/sema_decls.c | 3 ++- test/src/test_suite_runner.c3 | 2 +- test/test_suite/functions/invalid_test_vaarg.c3 | 1 + 4 files changed, 5 insertions(+), 2 deletions(-) create mode 100644 test/test_suite/functions/invalid_test_vaarg.c3 diff --git a/releasenotes.md b/releasenotes.md index 5a51d9e67..34905dca2 100644 --- a/releasenotes.md +++ b/releasenotes.md @@ -40,6 +40,7 @@ - Parse error in `$defined` was not handled correctly, leading to an assertion. - Assert when struct size would exceed 4 GB. - Assert when encountering a malformed module alias. +- Assert when encountering a test function with raw vaarg parameters. ### Stdlib changes - Add `ThreadPool` join function to wait for all threads to finish in the pool without destroying the threads. diff --git a/src/compiler/sema_decls.c b/src/compiler/sema_decls.c index 6fcad4f7b..8e8725ce2 100644 --- a/src/compiler/sema_decls.c +++ b/src/compiler/sema_decls.c @@ -4269,7 +4269,8 @@ static inline bool sema_analyse_func(SemaContext *context, Decl *decl, bool *era unsigned params = vec_size(sig->params); if (params) { - RETURN_SEMA_ERROR(sig->params[0], "%s functions may not take any parameters.", + SourceSpan span = sig->params[0] ? sig->params[0]->span : decl->span; + RETURN_SEMA_ERROR_AT(span, "%s functions may not take any parameters.", is_init_finalizer ? "'@init' and '@finalizer'" : "'@test' and '@benchmark'"); } TypeInfo *rtype_info = type_infoptr(sig->rtype); diff --git a/test/src/test_suite_runner.c3 b/test/src/test_suite_runner.c3 index 850e4771a..47d60afd6 100644 --- a/test/src/test_suite_runner.c3 +++ b/test/src/test_suite_runner.c3 @@ -299,7 +299,7 @@ fn bool parse_result(DString out, RunSettings settings, List{String}* cmdline, O if (!find_and_mark_error(&settings, ...parts[:5])) { - unexpected_errors.push(string::tformat(" - %s at %s:%s: \"%s\"", parts[0], parts[1].file_tbasename()!!, parts[2], parts[4])); + unexpected_errors.push(string::tformat(" - %s at %s:%s: %s", parts[0], parts[1].file_tbasename()!!, parts[2], parts[4])); } } diff --git a/test/test_suite/functions/invalid_test_vaarg.c3 b/test/test_suite/functions/invalid_test_vaarg.c3 new file mode 100644 index 000000000..7850b1634 --- /dev/null +++ b/test/test_suite/functions/invalid_test_vaarg.c3 @@ -0,0 +1 @@ +fn void asdf(...) @test; // #error: '@test' and '@benchmark' functions may not take any parameters. \ No newline at end of file