diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2023-10-01 12:00:17 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-10-01 12:00:17 -0700 |
| commit | 8e1421f19ef3daea9b8a414bd5783189bc292676 (patch) | |
| tree | cf642506120e82fed3de9c4a32a2232492d49b94 /test/behavior | |
| parent | d8bfbbbf25984cfdc4d50a92569523a0a151d9e6 (diff) | |
| parent | 0b1ba6eb521a15b38b08f9923dd84329487d5755 (diff) | |
| download | zig-8e1421f19ef3daea9b8a414bd5783189bc292676.tar.gz zig-8e1421f19ef3daea9b8a414bd5783189bc292676.zip | |
Merge pull request #17346 from Vexu/errSetCast
Sema: implement `@errSetCast` for error unions
Diffstat (limited to 'test/behavior')
| -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 |
