Fix pkg.Constant.field union access

This commit is contained in:
gingerBill
2026-06-29 11:06:34 +01:00
parent 138748c24a
commit feb9b6159e
2 changed files with 32 additions and 2 deletions

View File

@@ -32,6 +32,22 @@ enum ExactValueKind {
ExactValue_Count,
};
gb_global char const *exact_value_kind_string[ExactValue_Count] = {
"Invalid",
"Bool",
"String",
"Integer",
"Float",
"Complex",
"Quaternion",
"Pointer",
"Compound",
"Procedure",
"Typeid",
"String16",
};
struct ExactValue {
ExactValueKind kind;
union {

View File

@@ -972,6 +972,7 @@ gb_internal lbValue lb_const_value(lbModule *m, Type *type, ExactValue value, Ty
if (cl->elems.count == 0) {
return lb_const_nil(m, original_type);
}
value_type = type_of_expr(value.value_compound);
} else if (value.kind == ExactValue_Invalid) {
return lb_const_nil(m, original_type);
}
@@ -983,18 +984,31 @@ gb_internal lbValue lb_const_value(lbModule *m, Type *type, ExactValue value, Ty
i64 block_size = bt->Union.variant_block_size;
if (are_types_identical(value_type, original_type)) {
while (are_types_identical(value_type, original_type)) {
if (value.kind == ExactValue_Compound) {
ast_node(cl, CompoundLit, value.value_compound);
if (cl->elems.count == 0) {
return lb_const_nil(m, original_type);
}
value_type = type_of_expr(value.value_compound);
if (!are_types_identical(value_type, original_type)) {
break;
}
GB_PANIC("%s --> %s vs %s",
expr_to_string(value.value_compound),
temp_canonical_string(value_type), temp_canonical_string(original_type));
} else if (value.kind == ExactValue_Invalid) {
return lb_const_nil(m, original_type);
}
GB_PANIC("%s vs %s", type_to_string(value_type), type_to_string(original_type));
GB_PANIC("(value.kind=%s) %s vs %s",
exact_value_kind_string[value.kind],
temp_canonical_string(value_type), temp_canonical_string(original_type));
}
// union_multiple_allow_compound:;
lbValue cv = lb_const_value(m, value_type, value, value_type, cc);
Type *variant_type = cv.type;