mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-08 08:38:51 +00:00
Improve error messages when trying to access a non-existent field on a type
This commit is contained in:
@@ -4745,6 +4745,14 @@ gb_internal Entity *check_selector(CheckerContext *c, Operand *operand, Ast *nod
|
||||
gbString op_str = expr_to_string(op_expr);
|
||||
gbString type_str = type_to_string_shorthand(operand->type);
|
||||
gbString sel_str = expr_to_string(selector);
|
||||
|
||||
if (operand->mode == Addressing_Type) {
|
||||
if (is_type_polymorphic(operand->type, true)) {
|
||||
error(op_expr, "Type '%s' has no field nor polymorphic parameter '%s'", op_str, sel_str);
|
||||
} else {
|
||||
error(op_expr, "Type '%s' has no field '%s'", op_str, sel_str);
|
||||
}
|
||||
} else {
|
||||
error(op_expr, "'%s' of type '%s' has no field '%s'", op_str, type_str, sel_str);
|
||||
|
||||
if (operand->type != nullptr && selector->kind == Ast_Ident) {
|
||||
@@ -4761,6 +4769,7 @@ gb_internal Entity *check_selector(CheckerContext *c, Operand *operand, Ast *nod
|
||||
check_did_you_mean_type(name, bt->Enum.fields);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
gb_string_free(sel_str);
|
||||
gb_string_free(type_str);
|
||||
|
||||
Reference in New Issue
Block a user