| author | |
| committer | |
| log | ac95cfe4496a5504b42bf37b02f34eff390fe956 |
| tree | aae962f357e65bbba93146073f17adf2ec50c463 |
| parent | 49244dc0ca68d4b1282b7b26b52e750a4892fce2 |
| parent | 2ad6ca581da28a547b33d93f1a9855974a8b15c1 |
| signature |
3 files changed, 46 insertions(+), 0 deletions(-)
test/behavior/bugs/6305.zig created+10| ... | ... | @@ -0,0 +1,10 @@ |
| 1 | const ListNode = struct { | |
| 2 | next: ?*const @This() = null, | |
| 3 | }; | |
| 4 | ||
| 5 | test "copy array of self-referential struct" { | |
| 6 | comptime var nodes = [_]ListNode{ .{}, .{} }; | |
| 7 | nodes[0].next = &nodes[1]; | |
| 8 | const copy = nodes; | |
| 9 | _ = copy; | |
| 10 | } |
test/behavior/cast.zig+23| ... | ... | @@ -1154,6 +1154,29 @@ fn foobar(func: PFN_void) !void { |
| 1154 | 1154 | try std.testing.expect(@intFromPtr(func) == hardcoded_fn_addr); |
| 1155 | 1155 | } |
| 1156 | 1156 | |
| 1157 | test "cast function with an opaque parameter" { | |
| 1158 | const Container = struct { | |
| 1159 | const Ctx = opaque {}; | |
| 1160 | ctx: *Ctx, | |
| 1161 | func: *const fn (*Ctx) void, | |
| 1162 | }; | |
| 1163 | const Foo = struct { | |
| 1164 | x: i32, | |
| 1165 | y: i32, | |
| 1166 | fn funcImpl(self: *@This()) void { | |
| 1167 | self.x += 1; | |
| 1168 | self.y += 1; | |
| 1169 | } | |
| 1170 | }; | |
| 1171 | var foo = Foo{ .x = 100, .y = 200 }; | |
| 1172 | var c = Container{ | |
| 1173 | .ctx = @ptrCast(&foo), | |
| 1174 | .func = @ptrCast(&Foo.funcImpl), | |
| 1175 | }; | |
| 1176 | c.func(c.ctx); | |
| 1177 | try std.testing.expectEqual(foo, .{ .x = 101, .y = 201 }); | |
| 1178 | } | |
| 1179 | ||
| 1157 | 1180 | test "implicit ptr to *anyopaque" { |
| 1158 | 1181 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; |
| 1159 | 1182 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO |
test/cases/compile_errors/comptime_dereference_slice_of_struct.zig created+13| ... | ... | @@ -0,0 +1,13 @@ |
| 1 | const MyStruct = struct { x: bool = false }; | |
| 2 | ||
| 3 | comptime { | |
| 4 | const x = &[_]MyStruct{ .{}, .{} }; | |
| 5 | const y = x[0..1] ++ &[_]MyStruct{}; | |
| 6 | _ = y; | |
| 7 | } | |
| 8 | ||
| 9 | // error | |
| 10 | // backend=stage2 | |
| 11 | // target=native | |
| 12 | // | |
| 13 | // :5:16: error: comptime dereference requires '[1]tmp.MyStruct' to have a well-defined layout, but it does not. |