From efb7148a4574c608b21359fcbf2edf06afdb5e0c Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Tue, 28 Dec 2021 23:10:48 -0700 Subject: Sema: more union fixes * `Module.Union.getLayout`: fixes to support components of the union being 0 bits. * Implement `@typeInfo` for unions. * Add missing calls to `resolveTypeFields`. * Fix explicitly-provided union tag types passing a `Zir.Inst.Ref` where an `Air.Inst.Ref` was expected. We don't have any type safety for this; these typess are aliases. * Fix explicitly-provided `union(enum)` tag Values allocated to the wrong arena. --- src/type.zig | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src/type.zig') diff --git a/src/type.zig b/src/type.zig index feea1fe2c1..5bcf310fc4 100644 --- a/src/type.zig +++ b/src/type.zig @@ -2868,7 +2868,11 @@ pub const Type = extern union { /// Otherwise, returns `null`. pub fn unionTagType(ty: Type) ?Type { return switch (ty.tag()) { - .union_tagged => ty.castTag(.union_tagged).?.data.tag_ty, + .union_tagged => { + const union_obj = ty.castTag(.union_tagged).?.data; + assert(union_obj.haveFieldTypes()); + return union_obj.tag_ty; + }, .atomic_order, .atomic_rmw_op, -- cgit v1.2.3