diff options
| author | Veikka Tuominen <git@vexu.eu> | 2023-05-12 14:59:26 +0300 |
|---|---|---|
| committer | Veikka Tuominen <git@vexu.eu> | 2023-05-12 14:59:26 +0300 |
| commit | 5aa9628de3c6637f45b9d8cf8cbd19c422a74f6f (patch) | |
| tree | d85a0ff14b8b7b36458e12dca631f850b9707744 /test/behavior/error.zig | |
| parent | 0958d5d7db24222bdcc0fb8e8cdc9838953b9857 (diff) | |
| download | zig-5aa9628de3c6637f45b9d8cf8cbd19c422a74f6f.tar.gz zig-5aa9628de3c6637f45b9d8cf8cbd19c422a74f6f.zip | |
Sema: handle recursive inferred errors better in analyzeIsNonErrComptimeOnly
Closes #15669
Diffstat (limited to 'test/behavior/error.zig')
| -rw-r--r-- | test/behavior/error.zig | 41 |
1 files changed, 25 insertions, 16 deletions
diff --git a/test/behavior/error.zig b/test/behavior/error.zig index 91b5561d62..acb4b8fb61 100644 --- a/test/behavior/error.zig +++ b/test/behavior/error.zig @@ -678,22 +678,6 @@ test "error union payload is properly aligned" { if (blk.a != 1) unreachable; } -test "ret_ptr doesn't cause own inferred error set to be resolved" { - if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO - if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO - - const S = struct { - fn foo() !void {} - - fn doTheTest() !void { - errdefer @compileError("bad"); - - return try @This().foo(); - } - }; - try S.doTheTest(); -} - test "simple else prong allowed even when all errors handled" { if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO @@ -889,3 +873,28 @@ test "optional error set return type" { try expect(null == S.foo(true)); try expect(E.A == S.foo(false).?); } + +test "try used in recursive function with inferred error set" { + if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO + if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO + + const Value = union(enum) { + values: []const @This(), + b, + + fn x(value: @This()) !void { + switch (value.values[0]) { + .values => return try x(value.values[0]), + .b => return error.a, + } + } + }; + const a = Value{ + .values = &[1]Value{ + .{ + .values = &[1]Value{.{ .b = {} }}, + }, + }, + }; + try expectError(error.a, Value.x(a)); +} |
