Sema: implement union value equality at comptime

Still TODO is extern unions.
This commit is contained in:
Andrew Kelley
2022-02-26 18:01:12 -07:00
parent e999a925fa
commit 32e89a98d8
3 changed files with 27 additions and 2 deletions

View File

@@ -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());