master
1const expect = @import("std").testing.expect;
2const builtin = @import("builtin");
3
4const FormValue = union(enum) {
5 One: void,
6 Two: bool,
7};
8
9fn foo(id: u64) !FormValue {
10 return switch (id) {
11 2 => FormValue{ .Two = true },
12 1 => FormValue{ .One = {} },
13 else => return error.Whatever,
14 };
15}
16
17test "switch prong implicit cast" {
18 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
19 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
20 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
21
22 const result = switch (foo(2) catch unreachable) {
23 FormValue.One => false,
24 FormValue.Two => |x| x,
25 };
26 try expect(result);
27}