aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2023-02-21 23:16:25 +0000
committergingerBill <bill@gingerbill.org>2023-02-21 23:16:25 +0000
commitb9f7b2fdfaa41e9b4e48362d3bc1b839b62dd914 (patch)
tree65180b9f9545c14f84a7f83b1522ba61a97f3c86
parent59a601f2cf1f7575662e4e7f1c3cabd079280d0a (diff)
Improve error message for typed constants that cannot be represented by a type
-rw-r--r--src/check_expr.cpp15
1 files changed, 11 insertions, 4 deletions
diff --git a/src/check_expr.cpp b/src/check_expr.cpp
index 30e2c9ad8..c0920bde8 100644
--- a/src/check_expr.cpp
+++ b/src/check_expr.cpp
@@ -2116,16 +2116,21 @@ gb_internal bool check_is_expressible(CheckerContext *ctx, Operand *o, Type *typ
o->mode = Addressing_Invalid;
);
+ ERROR_BLOCK();
+
+
if (is_type_numeric(o->type) && is_type_numeric(type)) {
if (!is_type_integer(o->type) && is_type_integer(type)) {
error(o->expr, "'%s' truncated to '%s', got %s", a, b, s);
} else {
- ERROR_BLOCK();
- error(o->expr, "Cannot convert numeric value '%s' to '%s' from '%s', got %s", a, b, c, s);
+ if (are_types_identical(o->type, type)) {
+ error(o->expr, "Numeric value '%s' cannot be represented by '%s', got %s", a, c, s);
+ } else {
+ error(o->expr, "Cannot convert numeric value '%s' to '%s' from '%s', got %s", a, b, c, s);
+ }
check_assignment_error_suggestion(ctx, o, type);
}
} else {
- ERROR_BLOCK();
error(o->expr, "Cannot convert '%s' to '%s' from '%s', got %s", a, b, c, s);
check_assignment_error_suggestion(ctx, o, type);
}
@@ -2597,10 +2602,12 @@ gb_internal void check_shift(CheckerContext *c, Operand *x, Operand *y, Ast *nod
x->type = t_untyped_integer;
}
+ x->expr = node;
x->value = exact_value_shift(be->op.kind, x_val, y_val);
+
if (is_type_typed(x->type)) {
- check_is_expressible(c, x, base_type(x->type));
+ check_is_expressible(c, x, x->type);
}
return;
}