diff options
| author | gingerBill <bill@gingerbill.org> | 2024-04-17 13:31:32 +0100 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2024-04-17 13:31:32 +0100 |
| commit | 7cd2bc26f42237f825274198c5bc68f7633b73b1 (patch) | |
| tree | 6b4553c77ffff5e80b44cd72e76a6a6368c90f1f /src | |
| parent | a61ae7c861fa301684ee1582507061317b11426b (diff) | |
Clear error message on collisions with `using` on struct fields
Diffstat (limited to 'src')
| -rw-r--r-- | src/check_type.cpp | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/src/check_type.cpp b/src/check_type.cpp index 3bb1a4fd1..a6dbb8dfc 100644 --- a/src/check_type.cpp +++ b/src/check_type.cpp @@ -29,10 +29,11 @@ gb_internal void populate_using_array_index(CheckerContext *ctx, Ast *node, AstF } } -gb_internal void populate_using_entity_scope(CheckerContext *ctx, Ast *node, AstField *field, Type *t) { +gb_internal void populate_using_entity_scope(CheckerContext *ctx, Ast *node, AstField *field, Type *t, isize level) { if (t == nullptr) { return; } + Type *original_type = t; t = base_type(type_deref(t)); gbString str = nullptr; defer (gb_string_free(str)); @@ -46,16 +47,18 @@ gb_internal void populate_using_entity_scope(CheckerContext *ctx, Ast *node, Ast String name = f->token.string; Entity *e = scope_lookup_current(ctx->scope, name); if (e != nullptr && name != "_") { + gbString ot = type_to_string(original_type); // TODO(bill): Better type error if (str != nullptr) { - error(e->token, "'%.*s' is already declared in '%s'", LIT(name), str); + error(e->token, "'%.*s' is already declared in '%s', through 'using' from '%s'", LIT(name), str, ot); } else { - error(e->token, "'%.*s' is already declared", LIT(name)); + error(e->token, "'%.*s' is already declared, through 'using' from '%s'", LIT(name), ot); } + gb_string_free(ot); } else { add_entity(ctx, ctx->scope, nullptr, f); if (f->flags & EntityFlag_Using) { - populate_using_entity_scope(ctx, node, field, f->type); + populate_using_entity_scope(ctx, node, field, f->type, level+1); } } } @@ -200,7 +203,7 @@ gb_internal void check_struct_fields(CheckerContext *ctx, Ast *node, Slice<Entit continue; } - populate_using_entity_scope(ctx, node, p, type); + populate_using_entity_scope(ctx, node, p, type, 1); } if (is_subtype && p->names.count > 0) { |