aboutsummaryrefslogtreecommitdiff
path: root/src/check_expr.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/check_expr.cpp')
-rw-r--r--src/check_expr.cpp11
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;