zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit c9fc921abdfddcfed3383488dc1eaf23dcdeaa54 (tree)
parent 21b42af5aa6bc25dd99d2e425aa3df6bac80476e
Author: Matthew Lugg <mlugg@mlugg.co.uk>
Date:   Sun,  8 Feb 2026 15:14:57 +0000

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.

Diffstat:
Mtest/behavior/slice.zig | 2+-
Mtest/behavior/struct.zig | 23++++++++++++++++++++++-
2 files changed, 23 insertions(+), 2 deletions(-)

diff --git 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 @@ -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 }, + }); +}