According to the documentation https://ziglang.org/documentation/master/#Wrong-Union-Field-Access, the following should work, because extern and packed unions dont have the wrong field access check:
const MyUnion = packed union {
n: usize,
v: void,
fn new() @This() {
return MyUnion { .v = {} };
}
};
test "this should work at compiletime" {
comptime {
var myUnion = MyUnion.new();
var f = myUnion.n;
}
}
However, when running zig test, it errors:
error: accessing union field 'n' while field 'v' is set
var f = myUnion.n;