From 2fddd767ba20374e7677003c101e60f470c3804c Mon Sep 17 00:00:00 2001 From: kcbanner Date: Wed, 20 Sep 2023 23:53:06 -0400 Subject: sema: add support for unions in readFromMemory and writeToMemory --- src/type.zig | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'src/type.zig') diff --git a/src/type.zig b/src/type.zig index 0ed8c394fc..b440a23b9d 100644 --- a/src/type.zig +++ b/src/type.zig @@ -1929,8 +1929,12 @@ pub const Type = struct { pub fn unionFieldType(ty: Type, enum_tag: Value, mod: *Module) Type { const ip = &mod.intern_pool; const union_obj = mod.typeToUnion(ty).?; - const index = mod.unionTagFieldIndex(union_obj, enum_tag).?; - return union_obj.field_types.get(ip)[index].toType(); + const union_fields = union_obj.field_types.get(ip); + if (mod.unionTagFieldIndex(union_obj, enum_tag)) |index| { + return union_fields[index].toType(); + } else { + return mod.unionLargestField(union_obj).ty; + } } pub fn unionTagFieldIndex(ty: Type, enum_tag: Value, mod: *Module) ?u32 { -- cgit v1.2.3