Improve error positioning for #all_or_none

This commit is contained in:
gingerBill
2025-11-06 09:37:16 +00:00
parent 5bf3e0e87c
commit 4ce01854d5

View File

@@ -9857,6 +9857,12 @@ gb_internal void check_compound_literal_field_values(CheckerContext *c, Slice<As
}
if (missing_fields.count > 0) {
Ast *expr = o->expr;
if (expr == nullptr) {
GB_ASSERT(elems.count > 0);
expr = elems[elems.count-1];
}
ERROR_BLOCK();
if (build_context.terse_errors) {
@@ -9872,9 +9878,9 @@ gb_internal void check_compound_literal_field_values(CheckerContext *c, Slice<As
i += 1;
}
error(o->expr, "All or none of the fields must be assigned to a struct with '#all_or_none' applied, missing fields: %s", fields_string);
error(expr, "All or none of the fields must be assigned to a struct with '#all_or_none' applied, missing fields: %s", fields_string);
} else {
error(o->expr, "All or none of the fields must be assigned to a struct with '#all_or_none' applied, missing fields:");
error(expr, "All or none of the fields must be assigned to a struct with '#all_or_none' applied, missing fields:");
FOR_PTR_SET(field, missing_fields) {
gbString s = type_to_string(field->type);
error_line("\t%.*s: %s\n", LIT(field->token.string), s);