diff options
Diffstat (limited to 'src/checker.c')
| -rw-r--r-- | src/checker.c | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/checker.c b/src/checker.c index 32743d257..0788db920 100644 --- a/src/checker.c +++ b/src/checker.c @@ -208,6 +208,7 @@ typedef struct Scope { bool is_global; bool is_file; bool is_init; + bool has_been_imported; // This is only applicable to file scopes AstFile * file; } Scope; gb_global Scope *universal_scope = NULL; @@ -1529,6 +1530,10 @@ void check_all_global_entities(Checker *c) { } add_curr_ast_file(c, d->scope->file); + if (!d->scope->has_been_imported) { + continue; + } + if (e->kind != Entity_Procedure && str_eq(e->token.string, str_lit("main"))) { if (e->scope->is_init) { error(e->token, "`main` is reserved as the entry point procedure in the initial scope"); @@ -1606,6 +1611,12 @@ void check_import_entities(Checker *c, MapScope *file_scopes) { ast_node(id, ImportDecl, decl); Token token = id->relpath; + GB_ASSERT(parent_scope->is_file); + + if (!parent_scope->has_been_imported) { + continue; + } + HashKey key = hash_string(id->fullpath); Scope **found = map_scope_get(file_scopes, key); if (found == NULL) { @@ -1652,6 +1663,8 @@ void check_import_entities(Checker *c, MapScope *file_scopes) { warning(token, "Multiple #import of the same file within this scope"); } + scope->has_been_imported = true; + if (str_eq(id->import_name.string, str_lit("."))) { // NOTE(bill): Add imported entities to this file's scope for_array(elem_index, scope->elements.entries) { @@ -1721,6 +1734,7 @@ void check_import_entities(Checker *c, MapScope *file_scopes) { } } + String library_name = path_to_entity_name(fl->library_name.string, file_str); if (str_eq(library_name, str_lit("_"))) { error(fl->token, "File name, %.*s, cannot be as a library name as it is not a valid identifier", LIT(fl->library_name.string)); @@ -1755,6 +1769,10 @@ void check_parsed_files(Checker *c) { array_add(&c->global_scope->shared, scope); } + if (scope->is_init || scope->is_global) { + scope->has_been_imported = true; + } + f->scope = scope; f->decl_info = make_declaration_info(c->allocator, f->scope); HashKey key = hash_string(f->tokenizer.fullpath); |