aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorgingerBill <gingerBill@users.noreply.github.com>2025-10-30 09:16:19 +0000
committergingerBill <gingerBill@users.noreply.github.com>2025-10-30 09:16:19 +0000
commit0972690e14f1b7426e2c87bc2dd0152408657ff4 (patch)
tree49957abb33a8a7c00f49d465c8ee1fd5bb6ce399 /src
parent99520d82fd26316fc795ae524cc0dfa3477fdac8 (diff)
Add suggestion for `T[]` to be `[]T` if a type is allowed in that parsing context
Diffstat (limited to 'src')
-rw-r--r--src/parser.cpp14
1 files changed, 11 insertions, 3 deletions
diff --git a/src/parser.cpp b/src/parser.cpp
index 94c6083f7..152e55f8b 100644
--- a/src/parser.cpp
+++ b/src/parser.cpp
@@ -2739,7 +2739,7 @@ gb_internal Ast *parse_operand(AstFile *f, bool lhs) {
while (allow_token(f, Token_Comma)) {
Ast *dummy_name = parse_ident(f);
if (!err_once) {
- error(dummy_name, "'bit_field' fields do not support multiple names per field");
+ syntax_error(dummy_name, "'bit_field' fields do not support multiple names per field");
err_once = true;
}
}
@@ -3299,8 +3299,16 @@ gb_internal Ast *parse_atom_expr(AstFile *f, Ast *operand, bool lhs) {
open = expect_token(f, Token_OpenBracket);
if (f->curr_token.kind == Token_CloseBracket) {
- error(f->curr_token, "Expected an operand, got ]");
+ ERROR_BLOCK();
+ syntax_error(f->curr_token, "Expected an operand, got ]");
close = expect_token(f, Token_CloseBracket);
+
+ if (f->allow_type) {
+ gbString s = expr_to_string(operand);
+ error_line("\tSuggestion: If a type was wanted, did you mean '[]%s'?", s);
+ gb_string_free(s);
+ }
+
operand = ast_index_expr(f, operand, nullptr, open, close);
break;
}
@@ -6594,7 +6602,7 @@ gb_internal bool parse_file_tag(const String &lc, const Token &tok, AstFile *f)
} else if (lc == "no-instrumentation") {
f->flags |= AstFile_NoInstrumentation;
} else {
- error(tok, "Unknown tag '%.*s'", LIT(lc));
+ syntax_error(tok, "Unknown tag '%.*s'", LIT(lc));
}
return true;