| author | |
| committer | |
| log | c60896743d3b0776a44ac63582f51b6e64892528 |
| tree | 916e6ef4aa4647f3907ccf96001ff5350db992f3 |
| parent | 93e54f2354aa1b3de797a7ca5572bfa8c0f733f1 |
Closes #161302 files changed, 16 insertions(+), 1 deletions(-)
src/value.zig+9-1| ... | ... | @@ -745,7 +745,15 @@ pub const Value = struct { |
| 745 | 745 | .Extern => for (ty.structFields(mod).values(), 0..) |field, i| { |
| 746 | 746 | const off = @intCast(usize, ty.structFieldOffset(i, mod)); |
| 747 | 747 | const field_val = switch (val.ip_index) { |
| 748 | .none => val.castTag(.aggregate).?.data[i], | |
| 748 | .none => switch (val.tag()) { | |
| 749 | .bytes => { | |
| 750 | buffer[off] = val.castTag(.bytes).?.data[i]; | |
| 751 | continue; | |
| 752 | }, | |
| 753 | .aggregate => val.castTag(.aggregate).?.data[i], | |
| 754 | .repeated => val.castTag(.repeated).?.data, | |
| 755 | else => unreachable, | |
| 756 | }, | |
| 749 | 757 | else => switch (mod.intern_pool.indexToKey(val.toIntern()).aggregate.storage) { |
| 750 | 758 | .bytes => |bytes| { |
| 751 | 759 | buffer[off] = bytes[i]; |
test/behavior/comptime_memory.zig+7| ... | ... | @@ -431,3 +431,10 @@ test "dereference undefined pointer to zero-bit type" { |
| 431 | 431 | const p1: *[0]u32 = undefined; |
| 432 | 432 | try testing.expect(p1.*.len == 0); |
| 433 | 433 | } |
| 434 | ||
| 435 | test "type pun extern struct" { | |
| 436 | const S = extern struct { f: u8 }; | |
| 437 | comptime var s = S{ .f = 123 }; | |
| 438 | @ptrCast(*u8, &s).* = 72; | |
| 439 | try testing.expectEqual(@as(u8, 72), s.f); | |
| 440 | } |