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
signaturelock-open 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" {
3030 var runtime_index: usize = 1;
3131 _ = &runtime_index;
3232 const slice = @as(*align(4) [1]u8, &foo)[runtime_index..];
33 try expect(@TypeOf(slice) == []u8);
33 try expect(@TypeOf(slice) == []align(1) u8);
3434 try expect(slice.len == 0);
3535 try expect(@as(u2, @truncate(@intFromPtr(slice.ptr) - 1)) == 0);
3636}
3737
38test "default alignment allows unspecified in type syntax" {
39 try expect(*u32 == *align(@alignOf(u32)) u32);
38test "implicitly-aligned pointer is coercible to equivalent explicitly-aligned pointer" {
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();
4068}
4169
4270test "implicitly decreasing pointer alignment" {
test/behavior/generics.zig+1-4
......@@ -339,7 +339,7 @@ test "generic instantiation of tagged union with only one field" {
339339 try expect(S.foo(.{ .s = "ab" }) == 2);
340340}
341341
342test "nested generic function" {
342test "generic parameter type is function type" {
343343 if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest;
344344
345345 const S = struct {
......@@ -349,10 +349,7 @@ test "nested generic function" {
349349 fn bar(a: u32) anyerror!void {
350350 try expect(a == 123);
351351 }
352
353 fn g(_: *const fn (anytype) void) void {}
354352 };
355 try expect(@typeInfo(@TypeOf(S.g)).@"fn".is_generic);
356353 try S.foo(u32, S.bar, 123);
357354}
358355