Improve error messages when trying to access a non-existent field on a type

This commit is contained in:
gingerBill
2023-02-21 23:08:02 +00:00
parent b6a5c5f5d2
commit 59a601f2cf
+9
View File
@@ -4745,6 +4745,14 @@ gb_internal Entity *check_selector(CheckerContext *c, Operand *operand, Ast *nod
gbString op_str = expr_to_string(op_expr); gbString op_str = expr_to_string(op_expr);
gbString type_str = type_to_string_shorthand(operand->type); gbString type_str = type_to_string_shorthand(operand->type);
gbString sel_str = expr_to_string(selector); 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); 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) { 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); check_did_you_mean_type(name, bt->Enum.fields);
} }
} }
}
gb_string_free(sel_str); gb_string_free(sel_str);
gb_string_free(type_str); gb_string_free(type_str);