| 1 | const expectEqual = @import("std").testing.expectEqual; |
| 2 | |
| 3 | test "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 expectEqual(i32, @typeInfo(@TypeOf(foo)).error_union.payload); |
| 14 | |
| 15 | // Use compile-time reflection to access the error set type of an error union: |
| 16 | try comptime expectEqual(anyerror, @typeInfo(@TypeOf(foo)).error_union.error_set); |
| 17 | } |
| 18 | |
| 19 | // test |