zig/test/behavior/bugs/11213.zig
Jacob Young 525dcaecba behavior: enable stage2_c tests that are currently passing
Also fix C warnings triggered by these tests.
2022-10-25 05:11:28 -04:00

34 lines
626 B
Zig

const std = @import("std");
const builtin = @import("builtin");
const testing = std.testing;
test {
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,
}
}