mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-05 23:28:48 +00:00
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 == {} {
^~~~~~^
```
This commit is contained in:
+16
-5
@@ -2910,9 +2910,20 @@ gb_internal void check_comparison(CheckerContext *c, Ast *node, Operand *x, Oper
|
|||||||
if (!defined) {
|
if (!defined) {
|
||||||
gbString xs = type_to_string(x->type, temporary_allocator());
|
gbString xs = type_to_string(x->type, temporary_allocator());
|
||||||
gbString ys = type_to_string(y->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 {
|
} else {
|
||||||
Type *comparison_type = x->type;
|
Type *comparison_type = x->type;
|
||||||
if (x->type == err_type && is_operand_nil(*x)) {
|
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 {
|
} else {
|
||||||
yt = type_to_string(y->type);
|
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) {
|
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;
|
x->type = t_untyped_bool;
|
||||||
} else {
|
} else {
|
||||||
if (x->mode == Addressing_Constant &&
|
if (x->mode == Addressing_Constant &&
|
||||||
|
|||||||
Reference in New Issue
Block a user