Prohibit raw vaargs in regular functions with a function body.

This commit is contained in:
Christoffer Lerno
2025-01-03 15:36:42 +01:00
parent db4dc114f2
commit ad1511e69c
4 changed files with 16 additions and 1 deletions

View File

@@ -48,6 +48,7 @@
- Assert on add to uninitialized ct variable #1765.
- Dynamic function lookup fails after changing type without dummy anycast #1761
- $vasplat was allowed inside of a function when passed as an argument to a function.
- Prohibit raw vaargs in regular functions with a function body.
### Stdlib changes
- Increase BitWriter.write_bits limit up to 32 bits.

View File

@@ -3161,6 +3161,12 @@ bool sema_analyse_function_body(SemaContext *context, Decl *func)
if (!decl_ok(func)) return false;
Signature *signature = &func->func_decl.signature;
if (signature->variadic == VARIADIC_RAW)
{
RETURN_SEMA_ERROR(func, "C-style variadic arguments '...' are not supported for regular functions,"
" please use typed vaargs on the form 'int... args' or "
"untyped vaargs on the form 'args...' instead.");
}
FunctionPrototype *prototype = func->type->function.prototype;
ASSERT0(prototype);
context->original_inline_line = 0;

View File

@@ -0,0 +1,8 @@
import std;
fn void main()
{}
fn void bohoo(...) // #error: C-style variadic arguments
{
}

View File

@@ -1,7 +1,7 @@
import std;
def IList = List(<int>);
fn IList IList.new(...) @operator(construct)
fn IList IList.new() @operator(construct)
{
IList l;
l.new_init($vasplat); // #error: can only be used inside