aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2024-03-19 12:37:11 +0000
committergingerBill <bill@gingerbill.org>2024-03-19 12:37:11 +0000
commit89315986d4e4fb0977d98c2cfb8003763f5b93cf (patch)
treeaaf6c38147a1a718c94f6819de19e934d403b3a9 /src
parentec9ac593232d8e201639615ba075717dab066752 (diff)
Add suggestion when mistyping an array backwards e.g. `T[]`
Diffstat (limited to 'src')
-rw-r--r--src/check_type.cpp19
1 files changed, 18 insertions, 1 deletions
diff --git a/src/check_type.cpp b/src/check_type.cpp
index e71b35809..da4479f6e 100644
--- a/src/check_type.cpp
+++ b/src/check_type.cpp
@@ -3344,8 +3344,25 @@ gb_internal Type *check_type_expr(CheckerContext *ctx, Ast *e, Type *named_type)
if (!ok) {
gbString err_str = expr_to_string(e);
+ defer (gb_string_free(err_str));
+
+ ERROR_BLOCK();
error(e, "'%s' is not a type", err_str);
- gb_string_free(err_str);
+
+ Ast *node = unparen_expr(e);
+ if (node && node->kind == Ast_IndexExpr) {
+ gbString index_str = nullptr;
+ if (node->IndexExpr.index) {
+ index_str = expr_to_string(node->IndexExpr.index);
+ }
+ defer (gb_string_free(index_str));
+
+ gbString type_str = expr_to_string(node->IndexExpr.expr);
+ defer (gb_string_free(type_str));
+
+ error_line("\tSuggestion: Did you mean '[%s]%s'?", index_str ? index_str : "", type_str);
+ }
+
type = t_invalid;
}