Commit c60896743d
Changed files (2)
src
test
behavior
src/value.zig
@@ -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];
test/behavior/comptime_memory.zig
@@ -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);
+}