zig/test/cases/switch_prong_implicit_cast.zig

27 lines
464 B
Zig
Raw Normal View History

2017-01-05 00:57:48 -08:00
const assert = @import("std").debug.assert;
2016-12-25 15:31:57 -08:00
const FormValue = enum {
One,
Two: bool,
2016-12-25 15:31:57 -08:00
};
error Whatever;
fn foo(id: u64) -> %FormValue {
switch (id) {
2 => FormValue.Two { true },
1 => FormValue.One,
else => return error.Whatever,
}
}
fn switchProngImplicitCast() {
2016-12-25 15:31:57 -08:00
@setFnTest(this);
const result = switch (%%foo(2)) {
2016-12-25 15:31:57 -08:00
FormValue.One => false,
FormValue.Two => |x| x,
};
assert(result);
}