unions have a secret field for the type

See #144
This commit is contained in:
Andrew Kelley
2017-11-15 22:52:47 -05:00
parent f276fd0f37
commit 018cbff438
4 changed files with 195 additions and 31 deletions

View File

@@ -44,3 +44,16 @@ test "basic unions" {
foo.float = 12.34;
assert(foo.float == 12.34);
}
const FooExtern = extern union {
float: f64,
int: i32,
};
test "basic extern unions" {
var foo = FooExtern { .int = 1 };
assert(foo.int == 1);
foo.float = 12.34;
assert(foo.float == 12.34);
}