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" {...@@ -307,11 +307,15 @@ test "runtime-known array index has best alignment possible" {
307 if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest;307 if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest;
308308
309 // take full advantage of over-alignment309 // 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 };
311 comptime assert(@TypeOf(&array[0]) == *align(4) u8);311 comptime assert(@TypeOf(&array[0]) == *align(4) u8);
312 comptime assert(@TypeOf(&array[1]) == *u8);312 comptime assert(@TypeOf(&array[1]) == *align(1) u8);
313 comptime assert(@TypeOf(&array[2]) == *align(2) u8);313 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
316 // because align is too small but we still figure out to use 2320 // because align is too small but we still figure out to use 2
317 var bigger align(2) = [_]u64{ 1, 2, 3, 4 };321 var bigger align(2) = [_]u64{ 1, 2, 3, 4 };
...@@ -332,10 +336,14 @@ test "runtime-known array index has best alignment possible" {...@@ -332,10 +336,14 @@ test "runtime-known array index has best alignment possible" {
332 try testIndex(smaller[runtime_zero..].ptr, 3, *align(2) u32);336 try testIndex(smaller[runtime_zero..].ptr, 3, *align(2) u32);
333337
334 // has to use ABI alignment because index known at runtime only338 // has to use ABI alignment because index known at runtime only
335 try testIndex2(&array, 0, *u8);339 try testIndex2(&array, 0, *align(1) u8);
336 try testIndex2(&array, 1, *u8);340 try testIndex2(&array, 1, *align(1) u8);
337 try testIndex2(&array, 2, *u8);341 try testIndex2(&array, 2, *align(1) u8);
338 try testIndex2(&array, 3, *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);
339}347}
340fn testIndex(smaller: [*]align(2) u32, index: usize, comptime T: type) !void {348fn testIndex(smaller: [*]align(2) u32, index: usize, comptime T: type) !void {
341 comptime assert(@TypeOf(&smaller[index]) == T);349 comptime assert(@TypeOf(&smaller[index]) == T);
test/behavior/bitcast.zig-3
...@@ -350,9 +350,6 @@ test "comptime @bitCast packed struct to int and back" {...@@ -350,9 +350,6 @@ test "comptime @bitCast packed struct to int and back" {
350 iint_neg2: i3 = -2,350 iint_neg2: i3 = -2,
351 float: f32 = 3.14,351 float: f32 = 3.14,
352 @"enum": enum(u2) { A, B = 1, C, D } = .B,352 @"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 },
356 };353 };
357 const Int = @typeInfo(S).@"struct".backing_integer.?;354 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" {...@@ -551,19 +551,18 @@ test "generic function pointer can be called" {
551551
552test "value returned from comptime function is comptime known" {552test "value returned from comptime function is comptime known" {
553 const S = struct {553 const S = struct {
554 fn fields(comptime T: type) switch (@typeInfo(T)) {554 fn fieldCount(comptime T: type) switch (@typeInfo(T)) {
555 .@"struct" => []const std.builtin.Type.StructField,555 .@"struct" => comptime_int,
556 else => unreachable,556 else => unreachable,
557 } {557 } {
558 return switch (@typeInfo(T)) {558 return switch (@typeInfo(T)) {
559 .@"struct" => |info| info.fields,559 .@"struct" => |info| info.fields.len,
560 else => unreachable,560 else => unreachable,
561 };561 };
562 }562 }
563 };563 };
564 const fields_list = S.fields(@TypeOf(.{}));564 const fields_len = S.fieldCount(@TypeOf(.{}));
565 if (fields_list.len != 0)565 comptime assert(fields_len == 0);
566 @compileError("Argument count mismatch");
567}566}
568567
569test "registers get overwritten when ignoring return" {568test "registers get overwritten when ignoring return" {
test/behavior/eval.zig-7
...@@ -719,13 +719,6 @@ fn testVarInsideInlineLoop(args: anytype) !void {...@@ -719,13 +719,6 @@ fn testVarInsideInlineLoop(args: anytype) !void {
719 }719 }
720}720}
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
729test "array concatenation of function calls" {722test "array concatenation of function calls" {
730 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;723 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
731 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO724 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" {...@@ -820,7 +820,7 @@ test "packed struct passed to callconv(.c) function" {
820 if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest;820 if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest;
821821
822 const S = struct {822 const S = struct {
823 const Packed = packed struct {823 const Packed = packed struct(u64) {
824 a: u16,824 a: u16,
825 b: bool = true,825 b: bool = true,
826 c: bool = true,826 c: bool = true,
test/behavior/switch.zig+5-6
...@@ -645,7 +645,7 @@ test "switch prong pointer capture alignment" {...@@ -645,7 +645,7 @@ test "switch prong pointer capture alignment" {
645 }645 }
646646
647 switch (u) {647 switch (u) {
648 .a, .c => |*p| comptime assert(@TypeOf(p) == *const u8),648 .a, .c => |*p| comptime assert(@TypeOf(p) == *align(1) const u8),
649 .b => |*p| {649 .b => |*p| {
650 _ = p;650 _ = p;
651 return error.TestFailed;651 return error.TestFailed;
...@@ -1141,24 +1141,23 @@ test "decl literals as switch cases" {...@@ -1141,24 +1141,23 @@ test "decl literals as switch cases" {
1141 try comptime E.doTheTest(.foo);1141 try comptime E.doTheTest(.foo);
1142}1142}
11431143
1144// TODO audit after #15909 and/or #19855 are decided/implemented1144// TODO audit after #15909 and/or #19855 are decided/implemented.
1145// When we do that, consider adding an 'error{}' case if possible.
1145test "switch with uninstantiable union fields" {1146test "switch with uninstantiable union fields" {
1146 const U = union(enum) {1147 const U = union(enum) {
1147 ok: void,1148 ok: void,
1148 a: noreturn,1149 a: noreturn,
1149 b: noreturn,1150 b: noreturn,
1150 c: error{},
11511151
1152 fn doTheTest(u: @This()) void {1152 fn doTheTest(u: @This()) void {
1153 switch (u) {1153 switch (u) {
1154 .ok => {},1154 .ok => {},
1155 .a => comptime unreachable,1155 .a => comptime unreachable,
1156 .b => comptime unreachable,1156 .b => comptime unreachable,
1157 .c => comptime unreachable,
1158 }1157 }
1159 switch (u) {1158 switch (u) {
1160 .ok => {},1159 .ok => {},
1161 .a, .b, .c => comptime unreachable,1160 .a, .b => comptime unreachable,
1162 }1161 }
1163 switch (u) {1162 switch (u) {
1164 .ok => {},1163 .ok => {},
...@@ -1166,7 +1165,7 @@ test "switch with uninstantiable union fields" {...@@ -1166,7 +1165,7 @@ test "switch with uninstantiable union fields" {
1166 }1165 }
1167 switch (u) {1166 switch (u) {
1168 .a => comptime unreachable,1167 .a => comptime unreachable,
1169 .ok, .b, .c => {},1168 .ok, .b => {},
1170 }1169 }
1171 }1170 }
1172 };1171 };