This commit is contained in:
gingerBill
2026-03-15 17:15:16 +00:00
parent 0314c91a64
commit c51391f8cb
5 changed files with 37 additions and 9 deletions

View File

@@ -3375,7 +3375,7 @@ gb_internal bool union_variant_index_types_equal(Type *v, Type *vt) {
return false;
}
gb_internal i64 union_variant_index(Type *u, Type *v) {
gb_internal i64 union_variant_index_checked(Type *u, Type *v) {
u = base_type(u);
GB_ASSERT(u->kind == Type_Union);
@@ -3389,9 +3389,24 @@ gb_internal i64 union_variant_index(Type *u, Type *v) {
}
}
}
return 0;
GB_PANIC("unfound variant -> %s %s", type_to_string(u), type_to_string(v));
return -1;
}
gb_internal bool union_is_variant_of(Type *u, Type *v) {
u = base_type(u);
GB_ASSERT(u->kind == Type_Union);
for_array(i, u->Union.variants) {
Type *vt = u->Union.variants[i];
if (union_variant_index_types_equal(v, vt)) {
return true;
}
}
return false;
}
gb_internal i64 union_tag_size(Type *u) {
u = base_type(u);
GB_ASSERT(u->kind == Type_Union);