diff options
| author | gingerBill <gingerBill@users.noreply.github.com> | 2025-10-10 14:37:18 +0100 |
|---|---|---|
| committer | gingerBill <gingerBill@users.noreply.github.com> | 2025-10-10 14:37:18 +0100 |
| commit | 7e7b6ac0de9f34dd8efd08a9c6f303bcd25ed1cc (patch) | |
| tree | 617a68fb63b860e8f59ce902277b83a1533826df /src/check_expr.cpp | |
| parent | 943105bc7146d06408d37a373c04c958dac52c50 (diff) | |
Add short-circuit for `check_cast_internal`
Diffstat (limited to 'src/check_expr.cpp')
| -rw-r--r-- | src/check_expr.cpp | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/src/check_expr.cpp b/src/check_expr.cpp index d638cf97e..e22f12323 100644 --- a/src/check_expr.cpp +++ b/src/check_expr.cpp @@ -3239,6 +3239,9 @@ gb_internal void check_shift(CheckerContext *c, Operand *x, Operand *y, Ast *nod } gb_internal bool check_is_castable_to(CheckerContext *c, Operand *operand, Type *y) { + if (are_types_identical(operand->type, y)) { + return true; + } if (check_is_assignable_to(c, operand, y)) { return true; } @@ -3526,17 +3529,21 @@ 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, bt, &x->value)) { + 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, bt, &x->value)) { + if (check_representable_as_constant(c, x->value, type, &x->value)) { return true; } goto check_castable; + } else if (check_is_castable_to(c, x, type)) { + x->value = {}; + x->mode = Addressing_Value; + return true; } return false; |