- Support int $foo... arguments. #2601

This commit is contained in:
Christoffer Lerno
2025-11-26 23:54:18 +01:00
parent 8ec3a52ef7
commit 463c6957fc
9 changed files with 120 additions and 17 deletions

View File

@@ -0,0 +1,6 @@
macro foo2(int $a, $i...) // #error: Untyped constant vaargs are not supported. Use raw macro vaargs instead
{
$foreach $ab : $i:
$echo $ab;
$endforeach
}

View File

@@ -0,0 +1,4 @@
macro @foo3(int $a, int #i...) // #error: Expression parameters may not be vaargs, use untyped macro vaargs '...' instead
{
}

View File

@@ -1,3 +1,4 @@
// #target: macos-x64
fn void test1()
{
int x;

View File

@@ -0,0 +1,35 @@
// #target: macos-x64
module test;
macro foo(int $a, int... $i)
{
$foreach $ab : $i:
{
int x = $ab;
}
$endforeach
}
fn int main()
{
foo(3, 1, 2);
int[3] $x = { 1, 2, 3 };
foo(3, ...$x);
return 0;
}
/* #expect: test.ll
define i32 @main() #0 {
entry:
%x = alloca i32, align 4
%x1 = alloca i32, align 4
%x2 = alloca i32, align 4
%x3 = alloca i32, align 4
%x4 = alloca i32, align 4
store i32 1, ptr %x, align 4
store i32 2, ptr %x1, align 4
store i32 1, ptr %x2, align 4
store i32 2, ptr %x3, align 4
store i32 3, ptr %x4, align 4
ret i32 0
}

View File

@@ -0,0 +1,17 @@
module test;
macro foo(int $a, int... $i)
{
$foreach $ab : $i:
$echo $ab;
$endforeach
}
fn int main()
{
int a;
foo(3, 1, 2, a); // #error: All vaargs must be contant values
int[3] x = { 1, 2, 3 };
foo(3, ...x); // #error: The splat must be a compile time value
return 0;
}