From 6fdefef0527bef80ce4960a5e817c45234d1e58c Mon Sep 17 00:00:00 2001 From: Matthew Lugg Date: Wed, 11 Feb 2026 14:57:23 +0000 Subject: [PATCH] behavior: small tweaks for new semantics --- test/behavior/align.zig | 34 +++++++++++++++++++++++++++++++--- test/behavior/generics.zig | 5 +---- 2 files changed, 32 insertions(+), 7 deletions(-) diff --git a/test/behavior/align.zig b/test/behavior/align.zig index 2cbde2d56c..a59bed56ba 100644 --- 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 index 65a5a1b007..89ff5764a8 100644 --- 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); }