diff --git a/test/behavior/slice.zig b/test/behavior/slice.zig index 4de7b26d34f735b5a11976b3c3d05734e5f39e56..b13003dc5092f4395e211d24b2fef3baad0c05a4 100644 --- a/test/behavior/slice.zig +++ b/test/behavior/slice.zig @@ -160,7 +160,7 @@ test "slice of type" { test "pass a slice of types to a function" { const S = struct { - fn checkTypesSlice(types_slice: []const type) !void { + fn checkTypesSlice(comptime types_slice: []const type) !void { try expect(types_slice.len == 2); try expect(types_slice[0] == anyerror); try expect(types_slice[1] == bool); diff --git a/test/behavior/struct.zig b/test/behavior/struct.zig index 6422aef034bf3b4fbcf1e16acce3742944828a04..e6a355864629600f6294492ee11e4cf7c73f5674 100644 --- a/test/behavior/struct.zig +++ b/test/behavior/struct.zig @@ -2177,7 +2177,7 @@ test "avoid unused field function body compile error" { test "pass a pointer to a comptime-only struct field to a function" { const S = struct { - fn checkField(field_ptr: *const type) !void { + fn checkField(comptime field_ptr: *const type) !void { try expect(field_ptr.* == u42); } }; @@ -2233,3 +2233,24 @@ test "overaligned extern struct fields" { try expect(std.mem.isAligned(@intFromPtr(&e.c), @alignOf(u32))); try expect(std.mem.isAligned(@intFromPtr(&e.d), @alignOf(B))); } + +test "runtime-known slice of comptime-only struct" { + const Mixed = struct { index: u32, T: type }; + + const static = struct { + fn doTheTest(index_offset: usize, s: []const Mixed) !void { + for (s, index_offset..) |*mixed, index| { + try expect(mixed.index == index); + } + } + }; + + try static.doTheTest(10, &.{ + .{ .index = 10, .T = u8 }, + .{ .index = 11, .T = noreturn }, + .{ .index = 12, .T = *opaque {} }, + .{ .index = 13, .T = undefined }, + .{ .index = 14, .T = @TypeOf(undefined) }, + .{ .index = 15, .T = Mixed }, + }); +}