aboutsummaryrefslogtreecommitdiff
path: root/test/behavior/error.zig
diff options
context:
space:
mode:
authorVeikka Tuominen <git@vexu.eu>2023-10-01 13:16:02 +0300
committerVeikka Tuominen <git@vexu.eu>2023-10-01 17:00:01 +0300
commit63bd2bff12992aef0ce23ae4b344e9cb5d65f05d (patch)
treea26b65da14fca381be9266f41f504c332efc3c4b /test/behavior/error.zig
parentd8bfbbbf25984cfdc4d50a92569523a0a151d9e6 (diff)
downloadzig-63bd2bff12992aef0ce23ae4b344e9cb5d65f05d.tar.gz
zig-63bd2bff12992aef0ce23ae4b344e9cb5d65f05d.zip
Sema: add `@errorCast` which works for both error sets and error unions
Closes #17343
Diffstat (limited to 'test/behavior/error.zig')
-rw-r--r--test/behavior/error.zig20
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