aboutsummaryrefslogtreecommitdiff
path: root/src/type.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/type.zig')
-rw-r--r--src/type.zig8
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 {