aboutsummaryrefslogtreecommitdiff
path: root/test/behavior
diff options
context:
space:
mode:
authorVeikka Tuominen <git@vexu.eu>2023-05-13 12:52:16 +0300
committerGitHub <noreply@github.com>2023-05-13 12:52:16 +0300
commit68bacad8047df050c8ab6bf52c2921f482647d57 (patch)
tree9b428c397ee0173b670dfbe34f4c9330dc257bb7 /test/behavior
parent6f418c11e1ad1150fbdb002cfe1be92bda4e93cb (diff)
parent5aa9628de3c6637f45b9d8cf8cbd19c422a74f6f (diff)
downloadzig-68bacad8047df050c8ab6bf52c2921f482647d57.tar.gz
zig-68bacad8047df050c8ab6bf52c2921f482647d57.zip
Merge pull request #15643 from Vexu/fixes
make `@call` compile errors match regular calls
Diffstat (limited to 'test/behavior')
-rw-r--r--test/behavior/array.zig2
-rw-r--r--test/behavior/basic.zig7
-rw-r--r--test/behavior/error.zig41
3 files changed, 33 insertions, 17 deletions
diff --git a/test/behavior/array.zig b/test/behavior/array.zig
index fec8a7ac8a..b4754a59a4 100644
--- a/test/behavior/array.zig
+++ b/test/behavior/array.zig
@@ -696,7 +696,7 @@ test "array init of container level array variable" {
test "runtime initialized sentinel-terminated array literal" {
var c: u16 = 300;
const f = &[_:0x9999]u16{c};
- const g = @ptrCast(*[4]u8, f);
+ const g = @ptrCast(*const [4]u8, f);
try std.testing.expect(g[2] == 0x99);
try std.testing.expect(g[3] == 0x99);
}
diff --git a/test/behavior/basic.zig b/test/behavior/basic.zig
index db08442510..0de278fc57 100644
--- a/test/behavior/basic.zig
+++ b/test/behavior/basic.zig
@@ -1200,3 +1200,10 @@ test "arrays and vectors with big integers" {
try expect(b[0] == comptime std.math.maxInt(Int));
}
}
+
+test "pointer to struct literal with runtime field is constant" {
+ const S = struct { data: usize };
+ var runtime_zero: usize = 0;
+ const ptr = &S{ .data = runtime_zero };
+ try expect(@typeInfo(@TypeOf(ptr)).Pointer.is_const);
+}
diff --git a/test/behavior/error.zig b/test/behavior/error.zig
index 54d53eec4a..7e457c6456 100644
--- a/test/behavior/error.zig
+++ b/test/behavior/error.zig
@@ -705,22 +705,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
@@ -928,3 +912,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));
+}