zig/doc/langref/test_wrong_union_access.zig

12 lines
242 B
Zig

const Payload = union {
int: i64,
float: f64,
boolean: bool,
};
test "simple union" {
var payload = Payload{ .int = 1234 };
payload.float = 12.34;
}
// test_error=access of union field 'float' while field 'int' is active