mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
Add switch(variant)
This commit is contained in:
33
test/test_suite/variant/variant_switch.c3t
Normal file
33
test/test_suite/variant/variant_switch.c3t
Normal 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
|
||||
Reference in New Issue
Block a user