mirror of
https://github.com/odin-lang/Odin.git
synced 2026-01-18 10:37:01 +00:00
Treat *x as an unary operator to improve error messages for common C-programmer mistakes
This commit is contained in:
@@ -1800,6 +1800,19 @@ gb_internal bool check_unary_op(CheckerContext *c, Operand *o, Token op) {
|
||||
}
|
||||
break;
|
||||
|
||||
case Token_Mul:
|
||||
{
|
||||
ERROR_BLOCK();
|
||||
error(op, "Operator '%.*s' is not a valid unary operator in Odin", LIT(op.string));
|
||||
if (is_type_pointer(o->type)) {
|
||||
str = expr_to_string(o->expr);
|
||||
error_line("\tSuggestion: Did you mean '%s^'?\n", str);
|
||||
} else if (is_type_multi_pointer(o->type)) {
|
||||
str = expr_to_string(o->expr);
|
||||
error_line("\tSuggestion: The value is a multi-pointer, did you mean '%s[0]'?\n", str);
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
error(op, "Unknown operator '%.*s'", LIT(op.string));
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user