Skip to content

Commit e04d029

Browse files
committed
fixed: edge cases for smaller unions
1 parent fc0959e commit e04d029

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

compiler/src/symres.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -162,10 +162,10 @@ static SymresStatus symres_union_type(AstUnionType* u_node) {
162162
u_node->flags |= Ast_Flag_Comptime;
163163

164164
if (!u_node->tag_backing_type) {
165-
int n = (32 - bh_clz(bh_arr_length(u_node->variants))) >> 3;
166-
if (n <= 1) u_node->tag_backing_type = (AstType *) &basic_type_u8;
167-
else if (n == 2) u_node->tag_backing_type = (AstType *) &basic_type_u16;
168-
else if (n == 3) u_node->tag_backing_type = (AstType *) &basic_type_u32;
165+
int n = (31 - bh_clz(bh_arr_length(u_node->variants) - 1)) >> 3;
166+
if (n == 0) u_node->tag_backing_type = (AstType *) &basic_type_u8;
167+
else if (n == 1) u_node->tag_backing_type = (AstType *) &basic_type_u16;
168+
else if (n <= 3) u_node->tag_backing_type = (AstType *) &basic_type_u32;
169169
else {
170170
onyx_report_error(u_node->token->pos, Error_Critical, "Too many union variants. How did you even do this...?");
171171
return Symres_Error;

0 commit comments

Comments
 (0)