zig

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

commit 774911b4ce6c1aef44b33aee90ca341ab2fe669d (tree)
parent b00ef1aea1a456ad8b175534add8bb324cb39bba
Author: Matthew Lugg <mlugg@mlugg.co.uk>
Date:   Wed, 11 Feb 2026 14:57:23 +0000

behavior: small tweaks for new semantics

Diffstat:
Mtest/behavior/align.zig | 34+++++++++++++++++++++++++++++++---
Mtest/behavior/generics.zig | 5+----
2 files changed, 32 insertions(+), 7 deletions(-)

diff --git a/test/behavior/align.zig b/test/behavior/align.zig @@ -30,13 +30,41 @@ test "slicing array of length 1 can not assume runtime index is always zero" { var runtime_index: usize = 1; _ = &runtime_index; const slice = @as(*align(4) [1]u8, &foo)[runtime_index..]; - try expect(@TypeOf(slice) == []u8); + try expect(@TypeOf(slice) == []align(1) u8); try expect(slice.len == 0); try expect(@as(u2, @truncate(@intFromPtr(slice.ptr) - 1)) == 0); } -test "default alignment allows unspecified in type syntax" { - try expect(*u32 == *align(@alignOf(u32)) u32); +test "implicitly-aligned pointer is coercible to equivalent explicitly-aligned pointer" { + const A = *u32; + const B = *align(@alignOf(u32)) u32; + + comptime assert(A != B); + + const static = struct { + fn doTheTest() !void { + var buf: u32 = 123; + + const ptr: A = &buf; + const coerced_ptr: B = ptr; + + try expect(ptr == coerced_ptr); + try expect(ptr.* == 123); + try expect(coerced_ptr.* == 123); + + const ptr_ptr: *const A = &ptr; + const coerced_ptr_ptr: *const B = ptr_ptr; + + try expect(ptr_ptr == coerced_ptr_ptr); + try expect(ptr_ptr.* == &buf); + try expect(coerced_ptr_ptr.* == &buf); + try expect(ptr_ptr.*.* == 123); + try expect(coerced_ptr_ptr.*.* == 123); + } + }; + + try static.doTheTest(); + try comptime static.doTheTest(); } test "implicitly decreasing pointer alignment" { diff --git a/test/behavior/generics.zig b/test/behavior/generics.zig @@ -339,7 +339,7 @@ test "generic instantiation of tagged union with only one field" { try expect(S.foo(.{ .s = "ab" }) == 2); } -test "nested generic function" { +test "generic parameter type is function type" { if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest; const S = struct { @@ -349,10 +349,7 @@ test "nested generic function" { fn bar(a: u32) anyerror!void { try expect(a == 123); } - - fn g(_: *const fn (anytype) void) void {} }; - try expect(@typeInfo(@TypeOf(S.g)).@"fn".is_generic); try S.foo(u32, S.bar, 123); }