aboutsummaryrefslogtreecommitdiff
path: root/test/behavior/error.zig
diff options
context:
space:
mode:
authorVeikka Tuominen <git@vexu.eu>2024-01-02 17:33:41 +0200
committerAndrew Kelley <andrew@ziglang.org>2024-01-06 16:49:41 -0800
commit804cee3b93cb7084c16ee61d3bcb57f7d3c9f0bc (patch)
tree3d8c534b1adc352b248255ef2906ef2bdf11dffc /test/behavior/error.zig
parent282ff8d3bd4a0d870a98f145aa87039e0409b745 (diff)
downloadzig-804cee3b93cb7084c16ee61d3bcb57f7d3c9f0bc.tar.gz
zig-804cee3b93cb7084c16ee61d3bcb57f7d3c9f0bc.zip
categorize `behavior/bugs/<issueno>.zig` tests
Diffstat (limited to 'test/behavior/error.zig')
-rw-r--r--test/behavior/error.zig56
1 files changed, 56 insertions, 0 deletions
diff --git a/test/behavior/error.zig b/test/behavior/error.zig
index 715cd6e445..0caf09055e 100644
--- a/test/behavior/error.zig
+++ b/test/behavior/error.zig
@@ -970,3 +970,59 @@ test "try used in recursive function with inferred error set" {
};
try expectError(error.a, Value.x(a));
}
+
+test "generic inline function returns inferred error set" {
+ const S = struct {
+ inline fn retErr(comptime T: type) !T {
+ return error.AnError;
+ }
+
+ fn main0() !void {
+ _ = try retErr(u8);
+ }
+ };
+ S.main0() catch |e| {
+ try std.testing.expect(e == error.AnError);
+ };
+}
+
+test "function called at runtime is properly analyzed for inferred error set" {
+ if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
+ if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
+ if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
+
+ const S = struct {
+ fn foo() !void {
+ var a = true;
+ _ = &a;
+ if (a) return error.Foo;
+ return error.Bar;
+ }
+ fn bar() !void {
+ try @This().foo();
+ }
+ };
+
+ S.bar() catch |err| switch (err) {
+ error.Foo => {},
+ error.Bar => {},
+ };
+}
+
+test "generic type constructed from inferred error set of unresolved function" {
+ if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
+ if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
+ if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
+
+ const S = struct {
+ fn write(_: void, bytes: []const u8) !usize {
+ _ = bytes;
+ return 0;
+ }
+ const T = std.io.Writer(void, @typeInfo(@typeInfo(@TypeOf(write)).Fn.return_type.?).ErrorUnion.error_set, write);
+ fn writer() T {
+ return .{ .context = {} };
+ }
+ };
+ _ = std.io.multiWriter(.{S.writer()});
+}