| 1 | const expect = @import("std").testing.expect; |
| 2 | const builtin = @import("builtin"); |
| 3 | |
| 4 | const FormValue = union(enum) { |
| 5 | One: void, |
| 6 | Two: bool, |
| 7 | }; |
| 8 | |
| 9 | fn 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 | |
| 17 | test "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 | if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest; |
| 22 | |
| 23 | const result = switch (foo(2) catch unreachable) { |
| 24 | FormValue.One => false, |
| 25 | FormValue.Two => |x| x, |
| 26 | }; |
| 27 | try expect(result); |
| 28 | } |