| author | |
| committer | |
| log | ab3ac1e6701431ae7dea99b23852e36b369d6b87 |
| tree | 4c11613352cdd3f57f3079d3485a7da6fd5b3be7 |
| parent | 1606717b5fed83ee64ba1a91e55248e07a51afa6 |
Closes #172922 files changed, 18 insertions(+), 1 deletions(-)
src/value.zig+5-1| ... | @@ -398,7 +398,11 @@ pub const Value = struct { | ... | @@ -398,7 +398,11 @@ pub const Value = struct { |
| 398 | }, | 398 | }, |
| 399 | 399 | ||
| 400 | .un => |un| Tag.@"union".create(arena, .{ | 400 | .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 | }, | ||
| 402 | .val = un.val.toValue(), | 406 | .val = un.val.toValue(), |
| 403 | }), | 407 | }), |
| 404 | 408 |
test/behavior/union.zig+13| ... | @@ -1662,3 +1662,16 @@ test "union with 128 bit integer" { | ... | @@ -1662,3 +1662,16 @@ test "union with 128 bit integer" { |
| 1662 | } | 1662 | } |
| 1663 | } | 1663 | } |
| 1664 | } | 1664 | } |
| 1665 | |||
| 1666 | test "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 | } |