Fix constant conversion checks (#6104)

This commit is contained in:
ske
2026-01-07 02:19:41 -03:00
parent 94cc5d9e61
commit 91c1950b9f
2 changed files with 14 additions and 25 deletions

View File

@@ -3526,28 +3526,17 @@ gb_internal bool check_cast_internal(CheckerContext *c, Operand *x, Type *type)
Type *elem = core_array_type(bt);
if (core_type(bt)->kind == Type_Basic) {
if (check_representable_as_constant(c, x->value, type, &x->value)) {
return true;
}
goto check_castable;
} else if (!are_types_identical(elem, bt) &&
elem->kind == Type_Basic &&
check_representable_as_constant(c, x->value, elem, &x->value)) {
if (check_representable_as_constant(c, x->value, type, &x->value)) {
return true;
}
goto check_castable;
return check_representable_as_constant(c, x->value, type, &x->value) ||
(is_type_pointer(type) && check_is_castable_to(c, x, type));
} else if (!are_types_identical(elem, bt) && elem->kind == Type_Basic) {
return check_representable_as_constant(c, x->value, elem, &x->value) ||
(is_type_pointer(elem) && check_is_castable_to(c, x, elem));
} else if (check_is_castable_to(c, x, type)) {
x->value = {};
x->mode = Addressing_Value;
return true;
}
return false;
}
check_castable:
if (check_is_castable_to(c, x, type)) {
} else if (check_is_castable_to(c, x, type)) {
if (x->mode != Addressing_Constant) {
x->mode = Addressing_Value;
} else if (is_type_slice(type) && is_type_string(x->type)) {