From 32e89a98d82c0f4505a3f3d4cd72e7db2eadfbb9 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Sat, 26 Feb 2022 18:01:12 -0700 Subject: Sema: implement union value equality at comptime Still TODO is extern unions. --- src/type.zig | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src/type.zig') diff --git a/src/type.zig b/src/type.zig index ccf1b37471..68085500bc 100644 --- a/src/type.zig +++ b/src/type.zig @@ -2934,6 +2934,14 @@ pub const Type = extern union { }; } + /// Asserts the type is a union; returns the tag type, even if the tag will + /// not be stored at runtime. + pub fn unionTagTypeHypothetical(ty: Type) Type { + const union_obj = ty.cast(Payload.Union).?.data; + assert(union_obj.haveFieldTypes()); + return union_obj.tag_ty; + } + pub fn unionFields(ty: Type) Module.Union.Fields { const union_obj = ty.cast(Payload.Union).?.data; assert(union_obj.haveFieldTypes()); -- cgit v1.2.3