Commit 4e9f5f25c8
Changed files (3)
src/Sema.zig
@@ -4000,7 +4000,7 @@ fn resolveComptimeKnownAllocValue(sema: *Sema, block: *Block, alloc: Air.Inst.Re
const air_ptr_inst = Air.refToIndex(bin_op.lhs).?;
const tag_val = (try sema.resolveMaybeUndefVal(bin_op.rhs)).?;
const union_ty = sema.typeOf(bin_op.lhs).childType(mod);
- const payload_ty = union_ty.unionFieldType(tag_val, mod);
+ const payload_ty = union_ty.unionFieldType(tag_val, mod).?;
if (try sema.typeHasOnePossibleValue(payload_ty)) |payload_val| {
const new_ptr = ptr_mapping.get(air_ptr_inst).?;
const store_val = try mod.unionValue(union_ty, tag_val, payload_val);
src/type.zig
@@ -1646,8 +1646,12 @@ pub const Type = struct {
},
.union_type => |union_type| {
- if (opt_sema) |sema| try sema.resolveTypeFields(ty);
- if (ty.containerLayout(mod) != .Packed) {
+ const is_packed = ty.containerLayout(mod) == .Packed;
+ if (opt_sema) |sema| {
+ try sema.resolveTypeFields(ty);
+ if (is_packed) try sema.resolveTypeLayout(ty);
+ }
+ if (!is_packed) {
return (try ty.abiSizeAdvanced(mod, strat)).scalar * 8;
}
const union_obj = ip.loadUnionType(union_type);
src/TypedValue.zig
@@ -417,7 +417,7 @@ pub fn print(
try print(.{
.ty = field_ty,
.val = un.val.toValue(),
- }, writer, level - 1, mod);
+ }, writer, level - 1, mod);
} else {
try writer.writeAll("(no tag)");
}