From 7e64dedb7738cdfb6cddd9eb391629b3ad69dc8b Mon Sep 17 00:00:00 2001 From: gingerBill Date: Fri, 10 Oct 2025 14:31:41 +0100 Subject: [PATCH] Fix #5778 --- src/check_expr.cpp | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/src/check_expr.cpp b/src/check_expr.cpp index 8834091d1..d638cf97e 100644 --- a/src/check_expr.cpp +++ b/src/check_expr.cpp @@ -3523,20 +3523,27 @@ gb_internal bool check_cast_internal(CheckerContext *c, Operand *x, Type *type) Type *bt = base_type(type); if (is_const_expr && is_type_constant_type(bt)) { + Type *elem = core_array_type(bt); + if (core_type(bt)->kind == Type_Basic) { if (check_representable_as_constant(c, x->value, bt, &x->value)) { return true; - } else if (check_is_castable_to(c, x, type)) { - if (is_type_pointer(type)) { - return true; - } } - } else if (check_is_castable_to(c, x, type)) { - x->value = {}; - x->mode = Addressing_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, bt, &x->value)) { + return true; + } + goto check_castable; } - } else if (check_is_castable_to(c, x, type)) { + + return false; + } + +check_castable: + 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)) {