master
 1const expect = @import("std").testing.expect;
 2const builtin = @import("builtin");
 3
 4var read_count: u64 = 0;
 5
 6fn readOnce() anyerror!u64 {
 7    read_count += 1;
 8    return read_count;
 9}
10
11const FormValue = union(enum) {
12    Address: u64,
13    Other: bool,
14};
15
16fn doThing(form_id: u64) anyerror!FormValue {
17    return switch (form_id) {
18        17 => FormValue{ .Address = try readOnce() },
19        else => error.InvalidDebugInfo,
20    };
21}
22
23test "switch prong returns error enum" {
24    if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
25    if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
26    if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest;
27
28    switch (doThing(17) catch unreachable) {
29        FormValue.Address => |payload| {
30            try expect(payload == 1);
31        },
32        else => unreachable,
33    }
34    try expect(read_count == 1);
35}