aboutsummaryrefslogtreecommitdiff
path: root/test/behavior/error.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2022-05-24 17:53:04 -0700
committerAndrew Kelley <andrew@ziglang.org>2022-05-24 17:53:04 -0700
commit1f16b07d6fe43f96287b6cca8e8b58996199481f (patch)
tree5d16f515eea5c7a72466e352ce63e3de0a7ed53d /test/behavior/error.zig
parentc711c788f0a840f45d0d7423efe2f946b47caafb (diff)
downloadzig-1f16b07d6fe43f96287b6cca8e8b58996199481f.tar.gz
zig-1f16b07d6fe43f96287b6cca8e8b58996199481f.zip
stage2: treat `error{}!void` as a zero-bit type
Diffstat (limited to 'test/behavior/error.zig')
-rw-r--r--test/behavior/error.zig33
1 files changed, 30 insertions, 3 deletions
diff --git a/test/behavior/error.zig b/test/behavior/error.zig
index 4f316aeab2..312ab1524a 100644
--- a/test/behavior/error.zig
+++ b/test/behavior/error.zig
@@ -479,11 +479,38 @@ test "optional error set with only one error is the same size as bool" {
test "optional empty error set" {
if (builtin.zig_backend == .stage1) return error.SkipZigTest;
- const T = ?error{};
- var t: T = undefined;
- if (t != null) {
+ comptime try expect(@sizeOf(error{}!void) == @sizeOf(void));
+ comptime try expect(@alignOf(error{}!void) == @alignOf(void));
+
+ var x: ?error{} = undefined;
+ if (x != null) {
+ @compileError("test failed");
+ }
+}
+
+test "empty error set plus zero-bit payload" {
+ if (builtin.zig_backend == .stage1) return error.SkipZigTest;
+ if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
+ if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
+
+ comptime try expect(@sizeOf(error{}!void) == @sizeOf(void));
+ comptime try expect(@alignOf(error{}!void) == @alignOf(void));
+
+ var x: error{}!void = undefined;
+ if (x) |payload| {
+ if (payload != {}) {
+ @compileError("test failed");
+ }
+ } else |_| {
@compileError("test failed");
}
+ const S = struct {
+ fn empty() error{}!void {}
+ fn inferred() !void {
+ return empty();
+ }
+ };
+ try S.inferred();
}
test "nested catch" {