Value: handle more legacy tags when writing extern struct to memory
Closes #16130
This commit is contained in:
committed by
Andrew Kelley
parent
93e54f2354
commit
c60896743d
@@ -745,7 +745,15 @@ pub const Value = struct {
|
||||
.Extern => for (ty.structFields(mod).values(), 0..) |field, i| {
|
||||
const off = @intCast(usize, ty.structFieldOffset(i, mod));
|
||||
const field_val = switch (val.ip_index) {
|
||||
.none => val.castTag(.aggregate).?.data[i],
|
||||
.none => switch (val.tag()) {
|
||||
.bytes => {
|
||||
buffer[off] = val.castTag(.bytes).?.data[i];
|
||||
continue;
|
||||
},
|
||||
.aggregate => val.castTag(.aggregate).?.data[i],
|
||||
.repeated => val.castTag(.repeated).?.data,
|
||||
else => unreachable,
|
||||
},
|
||||
else => switch (mod.intern_pool.indexToKey(val.toIntern()).aggregate.storage) {
|
||||
.bytes => |bytes| {
|
||||
buffer[off] = bytes[i];
|
||||
|
||||
@@ -431,3 +431,10 @@ test "dereference undefined pointer to zero-bit type" {
|
||||
const p1: *[0]u32 = undefined;
|
||||
try testing.expect(p1.*.len == 0);
|
||||
}
|
||||
|
||||
test "type pun extern struct" {
|
||||
const S = extern struct { f: u8 };
|
||||
comptime var s = S{ .f = 123 };
|
||||
@ptrCast(*u8, &s).* = 72;
|
||||
try testing.expectEqual(@as(u8, 72), s.f);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user