authorgravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2026-02-08 15:14:57+00:00
committergravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2026-03-10 10:26:10+00:00
logc9fc921abdfddcfed3383488dc1eaf23dcdeaa54
tree275c01ebbf8b148ad33518bd8c152630aa52d1b8
parent21b42af5aa6bc25dd99d2e425aa3df6bac80476e
signature Commit is signed but in an unrecognized format.

tests: update for accepted language change

Pointers to comptime-only types (e.g. `*type`) are no longer themselves comptime-only types. This means explicit `comptime` annotations are required in a few more places. However, it also introduces the ability to access pointers to (including slices of) comptime-only types at runtime, provided only runtime fields are being accessed.

2 files changed, 23 insertions(+), 2 deletions(-)

test/behavior/slice.zig+1-1
......@@ -160,7 +160,7 @@ test "slice of type" {
160160
161161test "pass a slice of types to a function" {
162162 const S = struct {
163 fn checkTypesSlice(types_slice: []const type) !void {
163 fn checkTypesSlice(comptime types_slice: []const type) !void {
164164 try expect(types_slice.len == 2);
165165 try expect(types_slice[0] == anyerror);
166166 try expect(types_slice[1] == bool);
test/behavior/struct.zig+22-1
......@@ -2177,7 +2177,7 @@ test "avoid unused field function body compile error" {
21772177
21782178test "pass a pointer to a comptime-only struct field to a function" {
21792179 const S = struct {
2180 fn checkField(field_ptr: *const type) !void {
2180 fn checkField(comptime field_ptr: *const type) !void {
21812181 try expect(field_ptr.* == u42);
21822182 }
21832183 };
......@@ -2233,3 +2233,24 @@ test "overaligned extern struct fields" {
22332233 try expect(std.mem.isAligned(@intFromPtr(&e.c), @alignOf(u32)));
22342234 try expect(std.mem.isAligned(@intFromPtr(&e.d), @alignOf(B)));
22352235}
2236
2237test "runtime-known slice of comptime-only struct" {
2238 const Mixed = struct { index: u32, T: type };
2239
2240 const static = struct {
2241 fn doTheTest(index_offset: usize, s: []const Mixed) !void {
2242 for (s, index_offset..) |*mixed, index| {
2243 try expect(mixed.index == index);
2244 }
2245 }
2246 };
2247
2248 try static.doTheTest(10, &.{
2249 .{ .index = 10, .T = u8 },
2250 .{ .index = 11, .T = noreturn },
2251 .{ .index = 12, .T = *opaque {} },
2252 .{ .index = 13, .T = undefined },
2253 .{ .index = 14, .T = @TypeOf(undefined) },
2254 .{ .index = 15, .T = Mixed },
2255 });
2256}