zig/test/cases/switch_prong_implicit_cast.zig
Andrew Kelley 3c094116aa remove %% prefix operator
See #632
closes #545
closes #510

this makes #651 higher priority
2018-01-09 00:51:51 -05:00

25 lines
496 B
Zig

const assert = @import("std").debug.assert;
const FormValue = union(enum) {
One: void,
Two: bool,
};
error Whatever;
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);
}