From 4ce01854d57aa31c2b08a917b78ccff6f6d5c52e Mon Sep 17 00:00:00 2001 From: gingerBill Date: Thu, 6 Nov 2025 09:37:16 +0000 Subject: [PATCH] Improve error positioning for `#all_or_none` --- src/check_expr.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/check_expr.cpp b/src/check_expr.cpp index 677735c44..418fb5378 100644 --- a/src/check_expr.cpp +++ b/src/check_expr.cpp @@ -9857,6 +9857,12 @@ gb_internal void check_compound_literal_field_values(CheckerContext *c, Slice 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, Sliceexpr, "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);