authorgravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2026-02-09 10:41:56+00:00
committergravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2026-03-10 10:26:11+00:00
log09d0b1f87a740e968ef739e75729204ff470c98a
treecf478594c27665ef2bb9e4e363013d709cb77029
parent8d8140349fe2ea3197f8eea71cc120a0e8fa08d8
signaturelock-open Commit is signed but in an unrecognized format.

behavior: misc fixes

They compile now! They don't *pass*, but they *compile*!

6 files changed, 26 insertions(+), 30 deletions(-)

test/behavior/align.zig+15-7
......@@ -307,11 +307,15 @@ test "runtime-known array index has best alignment possible" {
307307 if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest;
308308
309309 // take full advantage of over-alignment
310 var array align(4) = [_]u8{ 1, 2, 3, 4 };
310 var array align(4) = [_]u8{ 1, 2, 3, 4, 5, 6, 7, 8 };
311311 comptime assert(@TypeOf(&array[0]) == *align(4) u8);
312 comptime assert(@TypeOf(&array[1]) == *u8);
312 comptime assert(@TypeOf(&array[1]) == *align(1) u8);
313313 comptime assert(@TypeOf(&array[2]) == *align(2) u8);
314 comptime assert(@TypeOf(&array[3]) == *u8);
314 comptime assert(@TypeOf(&array[3]) == *align(1) u8);
315 comptime assert(@TypeOf(&array[4]) == *align(4) u8);
316 comptime assert(@TypeOf(&array[5]) == *align(1) u8);
317 comptime assert(@TypeOf(&array[6]) == *align(2) u8);
318 comptime assert(@TypeOf(&array[7]) == *align(1) u8);
315319
316320 // because align is too small but we still figure out to use 2
317321 var bigger align(2) = [_]u64{ 1, 2, 3, 4 };
......@@ -332,10 +336,14 @@ test "runtime-known array index has best alignment possible" {
332336 try testIndex(smaller[runtime_zero..].ptr, 3, *align(2) u32);
333337
334338 // has to use ABI alignment because index known at runtime only
335 try testIndex2(&array, 0, *u8);
336 try testIndex2(&array, 1, *u8);
337 try testIndex2(&array, 2, *u8);
338 try testIndex2(&array, 3, *u8);
339 try testIndex2(&array, 0, *align(1) u8);
340 try testIndex2(&array, 1, *align(1) u8);
341 try testIndex2(&array, 2, *align(1) u8);
342 try testIndex2(&array, 3, *align(1) u8);
343 try testIndex2(&array, 4, *align(1) u8);
344 try testIndex2(&array, 5, *align(1) u8);
345 try testIndex2(&array, 6, *align(1) u8);
346 try testIndex2(&array, 7, *align(1) u8);
339347}
340348fn testIndex(smaller: [*]align(2) u32, index: usize, comptime T: type) !void {
341349 comptime assert(@TypeOf(&smaller[index]) == T);
test/behavior/bitcast.zig-3
......@@ -350,9 +350,6 @@ test "comptime @bitCast packed struct to int and back" {
350350 iint_neg2: i3 = -2,
351351 float: f32 = 3.14,
352352 @"enum": enum(u2) { A, B = 1, C, D } = .B,
353 vectorb: @Vector(3, bool) = .{ true, false, true },
354 vectori: @Vector(2, u8) = .{ 127, 42 },
355 vectorf: @Vector(2, f16) = .{ 3.14, 2.71 },
356353 };
357354 const Int = @typeInfo(S).@"struct".backing_integer.?;
358355
test/behavior/call.zig+5-6
......@@ -551,19 +551,18 @@ test "generic function pointer can be called" {
551551
552552test "value returned from comptime function is comptime known" {
553553 const S = struct {
554 fn fields(comptime T: type) switch (@typeInfo(T)) {
555 .@"struct" => []const std.builtin.Type.StructField,
554 fn fieldCount(comptime T: type) switch (@typeInfo(T)) {
555 .@"struct" => comptime_int,
556556 else => unreachable,
557557 } {
558558 return switch (@typeInfo(T)) {
559 .@"struct" => |info| info.fields,
559 .@"struct" => |info| info.fields.len,
560560 else => unreachable,
561561 };
562562 }
563563 };
564 const fields_list = S.fields(@TypeOf(.{}));
565 if (fields_list.len != 0)
566 @compileError("Argument count mismatch");
564 const fields_len = S.fieldCount(@TypeOf(.{}));
565 comptime assert(fields_len == 0);
567566}
568567
569568test "registers get overwritten when ignoring return" {
test/behavior/eval.zig-7
......@@ -719,13 +719,6 @@ fn testVarInsideInlineLoop(args: anytype) !void {
719719 }
720720}
721721
722test "*align(1) u16 is the same as *align(1:0:2) u16" {
723 comptime {
724 try expect(*align(1:0:2) u16 == *align(1) u16);
725 try expect(*align(2:0:2) u16 == *u16);
726 }
727}
728
729722test "array concatenation of function calls" {
730723 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
731724 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
test/behavior/packed-struct.zig+1-1
......@@ -820,7 +820,7 @@ test "packed struct passed to callconv(.c) function" {
820820 if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest;
821821
822822 const S = struct {
823 const Packed = packed struct {
823 const Packed = packed struct(u64) {
824824 a: u16,
825825 b: bool = true,
826826 c: bool = true,
test/behavior/switch.zig+5-6
......@@ -645,7 +645,7 @@ test "switch prong pointer capture alignment" {
645645 }
646646
647647 switch (u) {
648 .a, .c => |*p| comptime assert(@TypeOf(p) == *const u8),
648 .a, .c => |*p| comptime assert(@TypeOf(p) == *align(1) const u8),
649649 .b => |*p| {
650650 _ = p;
651651 return error.TestFailed;
......@@ -1141,24 +1141,23 @@ test "decl literals as switch cases" {
11411141 try comptime E.doTheTest(.foo);
11421142}
11431143
1144// TODO audit after #15909 and/or #19855 are decided/implemented
1144// TODO audit after #15909 and/or #19855 are decided/implemented.
1145// When we do that, consider adding an 'error{}' case if possible.
11451146test "switch with uninstantiable union fields" {
11461147 const U = union(enum) {
11471148 ok: void,
11481149 a: noreturn,
11491150 b: noreturn,
1150 c: error{},
11511151
11521152 fn doTheTest(u: @This()) void {
11531153 switch (u) {
11541154 .ok => {},
11551155 .a => comptime unreachable,
11561156 .b => comptime unreachable,
1157 .c => comptime unreachable,
11581157 }
11591158 switch (u) {
11601159 .ok => {},
1161 .a, .b, .c => comptime unreachable,
1160 .a, .b => comptime unreachable,
11621161 }
11631162 switch (u) {
11641163 .ok => {},
......@@ -1166,7 +1165,7 @@ test "switch with uninstantiable union fields" {
11661165 }
11671166 switch (u) {
11681167 .a => comptime unreachable,
1169 .ok, .b, .c => {},
1168 .ok, .b => {},
11701169 }
11711170 }
11721171 };