aboutsummaryrefslogtreecommitdiff
path: root/test/behavior
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2023-07-26 22:51:16 -0700
committerAndrew Kelley <andrew@ziglang.org>2023-07-27 10:12:08 -0700
commite66190025ffab39527da601980b7e3211069b6f5 (patch)
treea5ab77ea514c9993edcbd9335ad3904cebefd7bd /test/behavior
parent9a3adeea6ef0eb30e75e732148e0a2b93d0d0c99 (diff)
downloadzig-e66190025ffab39527da601980b7e3211069b6f5.tar.gz
zig-e66190025ffab39527da601980b7e3211069b6f5.zip
frontend: make fn calls byval; fix false positive isNonErr
This commit does two things which seem unrelated at first, but, together, solve a miscompilation, and potentially slightly speed up compiler perf, at the expense of making #2765 trickier to implement in the future. Sema: avoid returning a false positive for whether an inferred error set is comptime-known to be empty. AstGen: mark function calls as not being interested in a result location. This prevents the test case "ret_ptr doesn't cause own inferred error set to be resolved" from being regressed. If we want to accept and implement #2765 in the future, it will require solving this problem a different way, but the principle of YAGNI tells us to go ahead with this change. Old ZIR looks like this: %97 = ret_ptr() %101 = store_node(%97, %100) %102 = load(%97) %103 = ret_is_non_err(%102) New ZIR looks like this: %97 = ret_type() %101 = as_node(%97, %100) %102 = ret_is_non_err(%101) closes #15669
Diffstat (limited to 'test/behavior')
-rw-r--r--test/behavior/error.zig25
1 files changed, 25 insertions, 0 deletions
diff --git a/test/behavior/error.zig b/test/behavior/error.zig
index 1c4450a07f..4f26c9b18c 100644
--- a/test/behavior/error.zig
+++ b/test/behavior/error.zig
@@ -938,3 +938,28 @@ test "returning an error union containing a type with no runtime bits" {
var zero_byte: ZeroByteType = undefined;
(&zero_byte).* = try ZeroByteType.init();
}
+
+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));
+}