2024-04-25 01:41:47 +01:00
|
|
|
const expect = @import("std").testing.expect;
|
|
|
|
|
|
|
|
test "error union" {
|
|
|
|
var foo: anyerror!i32 = undefined;
|
|
|
|
|
|
|
|
// Coerce from child type of an error union:
|
|
|
|
foo = 1234;
|
|
|
|
|
|
|
|
// Coerce from an error set:
|
|
|
|
foo = error.SomeError;
|
|
|
|
|
|
|
|
// Use compile-time reflection to access the payload type of an error union:
|
2024-08-28 02:35:53 +01:00
|
|
|
try comptime expect(@typeInfo(@TypeOf(foo)).error_union.payload == i32);
|
2024-04-25 01:41:47 +01:00
|
|
|
|
|
|
|
// Use compile-time reflection to access the error set type of an error union:
|
2024-08-28 02:35:53 +01:00
|
|
|
try comptime expect(@typeInfo(@TypeOf(foo)).error_union.error_set == anyerror);
|
2024-04-25 01:41:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// test
|