aboutsummaryrefslogtreecommitdiff
path: root/test/behavior/error.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2022-12-27 13:46:57 -0700
committerAndrew Kelley <andrew@ziglang.org>2022-12-27 13:46:57 -0700
commitf4b067743f2ad25a1153153e3a89e0fe92837ea7 (patch)
tree85b06fc473b527aa60c04ce3b2e0fa6e2a86179f /test/behavior/error.zig
parent19056cb6821dd03612628e9220595576878aafe7 (diff)
downloadzig-f4b067743f2ad25a1153153e3a89e0fe92837ea7.tar.gz
zig-f4b067743f2ad25a1153153e3a89e0fe92837ea7.zip
add behavior test for optional error union return type
closes #1814
Diffstat (limited to 'test/behavior/error.zig')
-rw-r--r--test/behavior/error.zig13
1 files changed, 13 insertions, 0 deletions
diff --git a/test/behavior/error.zig b/test/behavior/error.zig
index fdf9091fe8..459799f5f6 100644
--- a/test/behavior/error.zig
+++ b/test/behavior/error.zig
@@ -889,3 +889,16 @@ test "field access of anyerror results in smaller error set" {
try expect(@TypeOf(E2.A) == E2);
try expect(@TypeOf(@field(anyerror, "NotFound")) == error{NotFound});
}
+
+test "optional error union return type" {
+ if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
+ if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
+
+ const S = struct {
+ fn foo() ?anyerror!u32 {
+ var x: u32 = 1234;
+ return @as(anyerror!u32, x);
+ }
+ };
+ try expect(1234 == try S.foo().?);
+}