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
signaturelock-open 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" {...@@ -160,7 +160,7 @@ test "slice of type" {
160160
161test "pass a slice of types to a function" {161test "pass a slice of types to a function" {
162 const S = struct {162 const S = struct {
163 fn checkTypesSlice(types_slice: []const type) !void {163 fn checkTypesSlice(comptime types_slice: []const type) !void {
164 try expect(types_slice.len == 2);164 try expect(types_slice.len == 2);
165 try expect(types_slice[0] == anyerror);165 try expect(types_slice[0] == anyerror);
166 try expect(types_slice[1] == bool);166 try expect(types_slice[1] == bool);
test/behavior/struct.zig+22-1
...@@ -2177,7 +2177,7 @@ test "avoid unused field function body compile error" {...@@ -2177,7 +2177,7 @@ test "avoid unused field function body compile error" {
21772177
2178test "pass a pointer to a comptime-only struct field to a function" {2178test "pass a pointer to a comptime-only struct field to a function" {
2179 const S = struct {2179 const S = struct {
2180 fn checkField(field_ptr: *const type) !void {2180 fn checkField(comptime field_ptr: *const type) !void {
2181 try expect(field_ptr.* == u42);2181 try expect(field_ptr.* == u42);
2182 }2182 }
2183 };2183 };
...@@ -2233,3 +2233,24 @@ test "overaligned extern struct fields" {...@@ -2233,3 +2233,24 @@ test "overaligned extern struct fields" {
2233 try expect(std.mem.isAligned(@intFromPtr(&e.c), @alignOf(u32)));2233 try expect(std.mem.isAligned(@intFromPtr(&e.c), @alignOf(u32)));
2234 try expect(std.mem.isAligned(@intFromPtr(&e.d), @alignOf(B)));2234 try expect(std.mem.isAligned(@intFromPtr(&e.d), @alignOf(B)));
2235}2235}
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}