authorgravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2026-02-08 14:21:08+00:00
committergravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2026-03-10 10:26:10+00:00
logda2006a38c63ac84aa9a075193bd72cf2d1716a2
tree794337cb06b934daddf1ee1d59a663d35d0b6125
parent4f7344dec0bc61916f0c9af99bc5b5e5b7167da3
signaturelock-open Commit is signed but in an unrecognized format.

tests: unions without fields need not store their tag at runtime

...because the union semantically has no possible value so cannot be stored to or loaded from memory anyway.

1 files changed, 1 insertions(+), 5 deletions(-)

test/behavior/union.zig+1-5
...@@ -1020,7 +1020,7 @@ test "containers with single-field enums" {...@@ -1020,7 +1020,7 @@ test "containers with single-field enums" {
1020 try comptime S.doTheTest();1020 try comptime S.doTheTest();
1021}1021}
10221022
1023test "@unionInit on union with tag but no fields" {1023test "@unionInit on union with u8 tag but no fields" {
1024 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO1024 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
1025 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO1025 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
10261026
...@@ -1036,10 +1036,6 @@ test "@unionInit on union with tag but no fields" {...@@ -1036,10 +1036,6 @@ test "@unionInit on union with tag but no fields" {
1036 }1036 }
1037 };1037 };
10381038
1039 comptime {
1040 assert(@sizeOf(Data) == 1);
1041 }
1042
1043 fn doTheTest() !void {1039 fn doTheTest() !void {
1044 var data: Data = .{ .no_op = {} };1040 var data: Data = .{ .no_op = {} };
1045 _ = &data;1041 _ = &data;