aboutsummaryrefslogtreecommitdiff
path: root/test/behavior/bugs/11213.zig
blob: 4699bda33335ce57ad00fdda58788d2a4c98f168 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
const std = @import("std");
const builtin = @import("builtin");
const testing = std.testing;

test {
    if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO

    const g: error{Test}!void = error.Test;

    var v: u32 = 0;
    hash(&v, g);
    try testing.expect(v == 1);
}

fn hash(v: *u32, key: anytype) void {
    const Key = @TypeOf(key);

    if (@typeInfo(Key) == .ErrorSet) {
        v.* += 1;
        return;
    }

    switch (@typeInfo(Key)) {
        .ErrorUnion => blk: {
            const payload = key catch |err| {
                hash(v, err);
                break :blk;
            };

            hash(v, payload);
        },

        else => unreachable,
    }
}