Add switch(variant)

This commit is contained in:
Christoffer Lerno
2021-12-09 22:52:48 +01:00
parent 0887d1e7dc
commit 379a66a14b
5 changed files with 83 additions and 6 deletions

View File

@@ -0,0 +1,33 @@
// #target: x64-darwin
module foo;
extern fn void printf(char*, ...);
fn void test(variant z)
{
switch (z)
{
case int:
printf("int: %d\n", *z);
*z = 3;
case double:
printf("double %f\n", *z);
default:
printf("Unknown type.\n");
}
if (z.typeid == int.typeid)
{
printf("int: %d\n", *(int*)(z));
}
}
fn int main()
{
test(&&123.0);
test(&&1);
test(&&true);
return 0;
}
/* expect: foo.ll
foekf