zig/test/cases/switch_prong_implicit_cast.zig
Andrew Kelley a35b366eb6 [breaking] delete ptr deref prefix op
start using zig-fmt-pointer-reform branch build of zig fmt
to fix code to use the new syntax

all of test/cases/* are processed, but there are more left
to be done - all the std lib used by the behavior tests
2018-04-30 20:35:54 -04:00

27 lines
518 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);
}