aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/behavior/cast.zig6
-rw-r--r--test/behavior/error.zig7
-rw-r--r--test/behavior/struct.zig25
3 files changed, 33 insertions, 5 deletions
diff --git a/test/behavior/cast.zig b/test/behavior/cast.zig
index 0ddbf6458a..50d99897c8 100644
--- a/test/behavior/cast.zig
+++ b/test/behavior/cast.zig
@@ -371,7 +371,9 @@ fn testPeerResolveArrayConstSlice(b: bool) !void {
}
test "implicitly cast from T to anyerror!?T" {
- if (builtin.zig_backend != .stage1) return error.SkipZigTest; // TODO
+ if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
+ if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
+ if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
try castToOptionalTypeError(1);
comptime try castToOptionalTypeError(1);
@@ -387,7 +389,7 @@ fn castToOptionalTypeError(z: i32) !void {
const f = z;
const g: anyerror!?i32 = f;
- _ = g catch {};
+ _ = try g;
const a = A{ .a = z };
const b: anyerror!?A = a;
diff --git a/test/behavior/error.zig b/test/behavior/error.zig
index 028bd26047..82814dc587 100644
--- a/test/behavior/error.zig
+++ b/test/behavior/error.zig
@@ -294,10 +294,11 @@ fn quux_1() !i32 {
}
test "error: Zero sized error set returned with value payload crash" {
- if (builtin.zig_backend != .stage1) return error.SkipZigTest; // TODO
+ if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
+ if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
- _ = foo3(0) catch {};
- _ = comptime foo3(0) catch {};
+ _ = try foo3(0);
+ _ = comptime try foo3(0);
}
const Error = error{};
diff --git a/test/behavior/struct.zig b/test/behavior/struct.zig
index a1d60632a9..1da2b0373d 100644
--- a/test/behavior/struct.zig
+++ b/test/behavior/struct.zig
@@ -1237,3 +1237,28 @@ test "anon init through error union" {
try S.doTheTest();
comptime try S.doTheTest();
}
+
+test "typed init through error unions and optionals" {
+ if (builtin.zig_backend == .stage1) return error.SkipZigTest;
+ if (builtin.zig_backend != .stage2_llvm) return error.SkipZigTest; // TODO
+
+ const S = struct {
+ a: u32,
+
+ fn foo() anyerror!?anyerror!@This() {
+ return @This(){ .a = 1 };
+ }
+ fn bar() ?anyerror![2]u8 {
+ return [2]u8{ 1, 2 };
+ }
+
+ fn doTheTest() !void {
+ var a = try (try foo()).?;
+ var b = try bar().?;
+ try expect(a.a + b[1] == 3);
+ }
+ };
+
+ try S.doTheTest();
+ comptime try S.doTheTest();
+}