diff options
Diffstat (limited to 'test/behavior/error.zig')
| -rw-r--r-- | test/behavior/error.zig | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/test/behavior/error.zig b/test/behavior/error.zig index 5a25714d14..2c3ba3b8c7 100644 --- a/test/behavior/error.zig +++ b/test/behavior/error.zig @@ -228,13 +228,29 @@ const Set1 = error{ A, B }; const Set2 = error{ A, C }; fn testExplicitErrorSetCast(set1: Set1) !void { - var x = @as(Set2, @errSetCast(set1)); + var x = @as(Set2, @errorCast(set1)); try expect(@TypeOf(x) == Set2); - var y = @as(Set1, @errSetCast(x)); + var y = @as(Set1, @errorCast(x)); try expect(@TypeOf(y) == Set1); try expect(y == error.A); } +test "@errorCast on error unions" { + const S = struct { + fn doTheTest() !void { + const casted: error{Bad}!i32 = @errorCast(retErrUnion()); + try expect((try casted) == 1234); + } + + fn retErrUnion() anyerror!i32 { + return 1234; + } + }; + + try S.doTheTest(); + try comptime S.doTheTest(); +} + test "comptime test error for empty error set" { if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
