authorgravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2026-02-11 14:57:23+00:00
committergravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2026-03-10 10:26:11+00:00
log774911b4ce6c1aef44b33aee90ca341ab2fe669d
tree50ebdc2d5aa73de086ff6524651e2d43b0cfabcc
parentb00ef1aea1a456ad8b175534add8bb324cb39bba
signature Commit is signed but in an unrecognized format.

behavior: small tweaks for new semantics


2 files changed, 32 insertions(+), 7 deletions(-)

test/behavior/align.zig+31-3
...@@ -30,13 +30,41 @@ test "slicing array of length 1 can not assume runtime index is always zero" {...@@ -30,13 +30,41 @@ test "slicing array of length 1 can not assume runtime index is always zero" {
30 var runtime_index: usize = 1;30 var runtime_index: usize = 1;
31 _ = &runtime_index;31 _ = &runtime_index;
32 const slice = @as(*align(4) [1]u8, &foo)[runtime_index..];32 const slice = @as(*align(4) [1]u8, &foo)[runtime_index..];
33 try expect(@TypeOf(slice) == []u8);33 try expect(@TypeOf(slice) == []align(1) u8);
34 try expect(slice.len == 0);34 try expect(slice.len == 0);
35 try expect(@as(u2, @truncate(@intFromPtr(slice.ptr) - 1)) == 0);35 try expect(@as(u2, @truncate(@intFromPtr(slice.ptr) - 1)) == 0);
36}36}
3737
38test "default alignment allows unspecified in type syntax" {38test "implicitly-aligned pointer is coercible to equivalent explicitly-aligned pointer" {
39 try expect(*u32 == *align(@alignOf(u32)) u32);39 const A = *u32;
40 const B = *align(@alignOf(u32)) u32;
41
42 comptime assert(A != B);
43
44 const static = struct {
45 fn doTheTest() !void {
46 var buf: u32 = 123;
47
48 const ptr: A = &buf;
49 const coerced_ptr: B = ptr;
50
51 try expect(ptr == coerced_ptr);
52 try expect(ptr.* == 123);
53 try expect(coerced_ptr.* == 123);
54
55 const ptr_ptr: *const A = &ptr;
56 const coerced_ptr_ptr: *const B = ptr_ptr;
57
58 try expect(ptr_ptr == coerced_ptr_ptr);
59 try expect(ptr_ptr.* == &buf);
60 try expect(coerced_ptr_ptr.* == &buf);
61 try expect(ptr_ptr.*.* == 123);
62 try expect(coerced_ptr_ptr.*.* == 123);
63 }
64 };
65
66 try static.doTheTest();
67 try comptime static.doTheTest();
40}68}
4169
42test "implicitly decreasing pointer alignment" {70test "implicitly decreasing pointer alignment" {
test/behavior/generics.zig+1-4
...@@ -339,7 +339,7 @@ test "generic instantiation of tagged union with only one field" {...@@ -339,7 +339,7 @@ test "generic instantiation of tagged union with only one field" {
339 try expect(S.foo(.{ .s = "ab" }) == 2);339 try expect(S.foo(.{ .s = "ab" }) == 2);
340}340}
341341
342test "nested generic function" {342test "generic parameter type is function type" {
343 if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest;343 if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest;
344344
345 const S = struct {345 const S = struct {
...@@ -349,10 +349,7 @@ test "nested generic function" {...@@ -349,10 +349,7 @@ test "nested generic function" {
349 fn bar(a: u32) anyerror!void {349 fn bar(a: u32) anyerror!void {
350 try expect(a == 123);350 try expect(a == 123);
351 }351 }
352
353 fn g(_: *const fn (anytype) void) void {}
354 };352 };
355 try expect(@typeInfo(@TypeOf(S.g)).@"fn".is_generic);
356 try S.foo(u32, S.bar, 123);353 try S.foo(u32, S.bar, 123);
357}354}
358355