diff --git a/src/Sema.zig b/src/Sema.zig index f741c2356e..e43804b521 100644 --- a/src/Sema.zig +++ b/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); diff --git a/src/TypedValue.zig b/src/TypedValue.zig index 600b132011..86f42813f7 100644 --- a/src/TypedValue.zig +++ b/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)"); } diff --git a/src/type.zig b/src/type.zig index 9eae7fca66..b6dbdd54f5 100644 --- a/src/type.zig +++ b/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);