authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2023-09-27 10:41:03+03:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-09-27 11:47:24-07:00
logab3ac1e6701431ae7dea99b23852e36b369d6b87
tree4c11613352cdd3f57f3079d3485a7da6fd5b3be7
parent1606717b5fed83ee64ba1a91e55248e07a51afa6

Value: fix assertion failure when mutating extern union

Closes #17292

2 files changed, 18 insertions(+), 1 deletions(-)

src/value.zig+5-1
......@@ -398,7 +398,11 @@ pub const Value = struct {
398398 },
399399
400400 .un => |un| Tag.@"union".create(arena, .{
401 .tag = un.tag.toValue(),
401 // toValue asserts that the value cannot be .none which is valid on unions.
402 .tag = .{
403 .ip_index = un.tag,
404 .legacy = undefined,
405 },
402406 .val = un.val.toValue(),
403407 }),
404408
test/behavior/union.zig+13
......@@ -1662,3 +1662,16 @@ test "union with 128 bit integer" {
16621662 }
16631663 }
16641664}
1665
1666test "memset extern union at comptime" {
1667 const U = extern union {
1668 foo: u8,
1669 };
1670 const u = comptime blk: {
1671 var u: U = undefined;
1672 @memset(std.mem.asBytes(&u), 0);
1673 u.foo = 0;
1674 break :blk u;
1675 };
1676 try expect(u.foo == 0);
1677}