aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeroen van Rijn <Kelimion@users.noreply.github.com>2025-05-03 22:31:01 +0200
committerJeroen van Rijn <Kelimion@users.noreply.github.com>2025-05-03 22:31:01 +0200
commitc96d8237ba1dfcc0db455bb8652ea7d8a947f817 (patch)
treeca90d0047a41aab79313e5a86c8e156c51e9cc2a
parent9681d88cd3d801f56456bdbe91fe437ebcda96cb (diff)
Clarify error messages for types that aren't simply comparable.
Previously, it implied that these are different types: ``` W:/Scratch/scratch.odin(17:5) Error: Cannot compare expression, operator '==' not defined between the types 'Handle_Map($T=u32, $HT=u32, $Max=10000)' and 'Handle_Map($T=u32, $HT=u32, $Max=10000)' if m == {} { ^~~~~~^ ``` Now: ``` W:/Scratch/scratch.odin(20:5) Error: Cannot compare expression. Type 'Handle_Map($T=u32, $HT=u32, $Max=10000)' is not simply comparable, so operator '==' is not defined for it. if m == {} { ^~~~~~^ ```
-rw-r--r--src/check_expr.cpp21
1 files changed, 16 insertions, 5 deletions
diff --git a/src/check_expr.cpp b/src/check_expr.cpp
index 6f585fe73..10b37bbf3 100644
--- a/src/check_expr.cpp
+++ b/src/check_expr.cpp
@@ -2910,9 +2910,20 @@ gb_internal void check_comparison(CheckerContext *c, Ast *node, Operand *x, Oper
if (!defined) {
gbString xs = type_to_string(x->type, temporary_allocator());
gbString ys = type_to_string(y->type, temporary_allocator());
- err_str = gb_string_make(temporary_allocator(),
- gb_bprintf("operator '%.*s' not defined between the types '%s' and '%s'", LIT(token_strings[op]), xs, ys)
- );
+
+ if (!is_type_comparable(x->type)) {
+ err_str = gb_string_make(temporary_allocator(),
+ gb_bprintf("Type '%s' is not simply comparable, so operator '%.*s' is not defined for it", xs, LIT(token_strings[op]))
+ );
+ } else if (!is_type_comparable(y->type)) {
+ err_str = gb_string_make(temporary_allocator(),
+ gb_bprintf("Type '%s' is not simply comparable, so operator '%.*s' is not defined for it", ys, LIT(token_strings[op]))
+ );
+ } else {
+ err_str = gb_string_make(temporary_allocator(),
+ gb_bprintf("Operator '%.*s' not defined between the types '%s' and '%s'", LIT(token_strings[op]), xs, ys)
+ );
+ }
} else {
Type *comparison_type = x->type;
if (x->type == err_type && is_operand_nil(*x)) {
@@ -2933,11 +2944,11 @@ gb_internal void check_comparison(CheckerContext *c, Ast *node, Operand *x, Oper
} else {
yt = type_to_string(y->type);
}
- err_str = gb_string_make(temporary_allocator(), gb_bprintf("mismatched types '%s' and '%s'", xt, yt));
+ err_str = gb_string_make(temporary_allocator(), gb_bprintf("Mismatched types '%s' and '%s'", xt, yt));
}
if (err_str != nullptr) {
- error(node, "Cannot compare expression, %s", err_str);
+ error(node, "Cannot compare expression. %s.", err_str);
x->type = t_untyped_bool;
} else {
if (x->mode == Addressing_Constant &&