Merge pull request #16721 from hryx/stage1-coverage
This commit is contained in:
10
test/behavior/bugs/6305.zig
Normal file
10
test/behavior/bugs/6305.zig
Normal file
@@ -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;
|
||||
}
|
||||
@@ -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
|
||||
|
||||
@@ -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.
|
||||
Reference in New Issue
Block a user