From f9654b6c368d21d665850f4d6f75ebffdf313854 Mon Sep 17 00:00:00 2001 From: gingerBill Date: Wed, 7 Nov 2018 16:11:14 +0000 Subject: Fix package usage with `when` on `import` #278 --- src/checker.cpp | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'src/checker.cpp') diff --git a/src/checker.cpp b/src/checker.cpp index 9a8f065ff..5daefc896 100644 --- a/src/checker.cpp +++ b/src/checker.cpp @@ -657,7 +657,6 @@ void init_checker(Checker *c, Parser *parser) { init_checker_info(&c->info); array_init(&c->procs_to_check, a); - ptr_set_init(&c->checked_packages, a); // NOTE(bill): Is this big enough or too small? isize item_size = gb_max3(gb_size_of(Entity), gb_size_of(Type), gb_size_of(Scope)); @@ -673,7 +672,6 @@ void destroy_checker(Checker *c) { destroy_checker_info(&c->info); array_free(&c->procs_to_check); - ptr_set_destroy(&c->checked_packages); destroy_checker_context(&c->init_ctx); } @@ -2370,6 +2368,10 @@ void check_all_global_entities(Checker *c) { GB_ASSERT(ctx.pkg != nullptr); GB_ASSERT(e->pkg != nullptr); + if (!e->pkg->used) { + continue; + } + if (pkg->kind == Package_Init) { if (e->kind != Entity_Procedure && e->token.string == "main") { error(e->token, "'main' is reserved as the entry point procedure in the initial scope"); @@ -2635,8 +2637,10 @@ void check_add_import_decl(CheckerContext *ctx, Ast *decl) { if (id->fullpath == "builtin") { scope = builtin_pkg->scope; + builtin_pkg->used = true; } else if (id->fullpath == "intrinsics") { scope = intrinsics_pkg->scope; + intrinsics_pkg->used = true; } else { HashKey key = hash_string(id->fullpath); AstPackage **found = map_get(pkgs, key); @@ -2649,7 +2653,7 @@ void check_add_import_decl(CheckerContext *ctx, Ast *decl) { GB_PANIC("Unable to find scope for package: %.*s", LIT(id->fullpath)); } else { AstPackage *pkg = *found; - ptr_set_add(&ctx->checker->checked_packages, pkg); + pkg->used = true; scope = pkg->scope; } } @@ -2765,9 +2769,9 @@ bool collect_checked_packages_from_decl_list(Checker *c, Array const &dec continue; } AstPackage *pkg = *found; - if (!ptr_set_exists(&c->checked_packages, pkg)) { + if (!pkg->used) { new_files = true; - ptr_set_add(&c->checked_packages, pkg); + pkg->used = true; } case_end; } @@ -2996,7 +3000,7 @@ void check_import_entities(Checker *c) { switch (pkg->kind) { case Package_Init: case Package_Runtime: - ptr_set_add(&c->checked_packages, pkg); + pkg->used = true; break; } } @@ -3007,7 +3011,7 @@ void check_import_entities(Checker *c) { ImportGraphNode *node = package_order[i]; GB_ASSERT(node->scope->flags&ScopeFlag_Pkg); AstPackage *pkg = node->scope->pkg; - if (!ptr_set_exists(&c->checked_packages, pkg)) { + if (!pkg->used) { continue; } @@ -3028,7 +3032,7 @@ void check_import_entities(Checker *c) { ImportGraphNode *node = package_order[pkg_index]; AstPackage *pkg = node->pkg; - if (!ptr_set_exists(&c->checked_packages, pkg)) { + if (!pkg->used) { continue; } -- cgit v1.2.3