zig/test/cases/switch_prong_implicit_cast.zig
Jimmi Holst Christensen 8139c5a516
New Zig formal grammar (#1685)
Reverted #1628 and changed the grammar+parser of the language to not allow certain expr where types are expected
2018-11-13 05:08:37 -08:00

23 lines
474 B
Zig

const assert = @import("std").debug.assert;
const FormValue = union(enum) {
One: void,
Two: bool,
};
fn foo(id: u64) !FormValue {
return switch (id) {
2 => FormValue{ .Two = true },
1 => FormValue{ .One = {} },
else => return error.Whatever,
};
}
test "switch prong implicit cast" {
const result = switch (foo(2) catch unreachable) {
FormValue.One => false,
FormValue.Two => |x| x,
};
assert(result);
}