zig/test/behavior/switch_prong_implicit_cast.zig

27 lines
733 B
Zig
Raw Normal View History

const expect = @import("std").testing.expect;
const builtin = @import("builtin");
2017-01-05 08:57:48 +00:00
const FormValue = union(enum) {
One: void,
Two: bool,
2016-12-25 23:31:57 +00:00
};
2018-02-01 03:48:40 +00:00
fn foo(id: u64) !FormValue {
return switch (id) {
2 => FormValue{ .Two = true },
1 => FormValue{ .One = {} },
else => return error.Whatever,
};
}
2017-05-24 02:38:31 +01:00
test "switch prong implicit cast" {
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
const result = switch (foo(2) catch unreachable) {
2016-12-25 23:31:57 +00:00
FormValue.One => false,
FormValue.Two => |x| x,
};
try expect(result);
}