aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--test/behavior/bugs/6305.zig10
-rw-r--r--test/behavior/cast.zig23
-rw-r--r--test/cases/compile_errors/comptime_dereference_slice_of_struct.zig13
3 files changed, 46 insertions, 0 deletions
diff --git a/test/behavior/bugs/6305.zig b/test/behavior/bugs/6305.zig
new file mode 100644
index 0000000000..6912944ad1
--- /dev/null
+++ b/test/behavior/bugs/6305.zig
@@ -0,0 +1,10 @@
+const ListNode = struct {
+ next: ?*const @This() = null,
+};
+
+test "copy array of self-referential struct" {
+ comptime var nodes = [_]ListNode{ .{}, .{} };
+ nodes[0].next = &nodes[1];
+ const copy = nodes;
+ _ = copy;
+}
diff --git a/test/behavior/cast.zig b/test/behavior/cast.zig
index aa1a24bc9b..742f6b5af5 100644
--- a/test/behavior/cast.zig
+++ b/test/behavior/cast.zig
@@ -1154,6 +1154,29 @@ fn foobar(func: PFN_void) !void {
try std.testing.expect(@intFromPtr(func) == hardcoded_fn_addr);
}
+test "cast function with an opaque parameter" {
+ const Container = struct {
+ const Ctx = opaque {};
+ ctx: *Ctx,
+ func: *const fn (*Ctx) void,
+ };
+ const Foo = struct {
+ x: i32,
+ y: i32,
+ fn funcImpl(self: *@This()) void {
+ self.x += 1;
+ self.y += 1;
+ }
+ };
+ var foo = Foo{ .x = 100, .y = 200 };
+ var c = Container{
+ .ctx = @ptrCast(&foo),
+ .func = @ptrCast(&Foo.funcImpl),
+ };
+ c.func(c.ctx);
+ try std.testing.expectEqual(foo, .{ .x = 101, .y = 201 });
+}
+
test "implicit ptr to *anyopaque" {
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
diff --git a/test/cases/compile_errors/comptime_dereference_slice_of_struct.zig b/test/cases/compile_errors/comptime_dereference_slice_of_struct.zig
new file mode 100644
index 0000000000..8d3619d906
--- /dev/null
+++ b/test/cases/compile_errors/comptime_dereference_slice_of_struct.zig
@@ -0,0 +1,13 @@
+const MyStruct = struct { x: bool = false };
+
+comptime {
+ const x = &[_]MyStruct{ .{}, .{} };
+ const y = x[0..1] ++ &[_]MyStruct{};
+ _ = y;
+}
+
+// error
+// backend=stage2
+// target=native
+//
+// :5:16: error: comptime dereference requires '[1]tmp.MyStruct' to have a well-defined layout, but it does not.