diff options
| author | kcbanner <kcbanner@gmail.com> | 2023-09-20 23:53:06 -0400 |
|---|---|---|
| committer | kcbanner <kcbanner@gmail.com> | 2023-09-23 13:04:56 -0400 |
| commit | 2fddd767ba20374e7677003c101e60f470c3804c (patch) | |
| tree | 91ffbed5086771488201cebd82be6e1554ac14b5 /src/type.zig | |
| parent | ce919ccf45951856a762ffdb8ef850301cd8c588 (diff) | |
| download | zig-2fddd767ba20374e7677003c101e60f470c3804c.tar.gz zig-2fddd767ba20374e7677003c101e60f470c3804c.zip | |
sema: add support for unions in readFromMemory and writeToMemory
Diffstat (limited to 'src/type.zig')
| -rw-r--r-- | src/type.zig | 8 |
1 files changed, 6 insertions, 2 deletions
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 { |
