master
1const expect = @import("std").testing.expect;
2
3test "error union" {
4 var foo: anyerror!i32 = undefined;
5
6 // Coerce from child type of an error union:
7 foo = 1234;
8
9 // Coerce from an error set:
10 foo = error.SomeError;
11
12 // Use compile-time reflection to access the payload type of an error union:
13 try comptime expect(@typeInfo(@TypeOf(foo)).error_union.payload == i32);
14
15 // Use compile-time reflection to access the error set type of an error union:
16 try comptime expect(@typeInfo(@TypeOf(foo)).error_union.error_set == anyerror);
17}
18
19// test