From 7624ecf4ba2a14611a80000f2b3de06b1eb0724e Mon Sep 17 00:00:00 2001 From: Laytan Laats Date: Sat, 31 Aug 2024 02:30:32 +0200 Subject: [PATCH 1/2] fix some issues with the "bad import name" errors There was so much wrong here: - The `if` statement was never entered because even on invalid import names `path_to_entity_name` returns "_" - Two errors were shown where one doesn't make sense, need to choose one based on context - Structure of the messages were different from other error messages - Suggestion was using the wrong import path --- src/checker.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/checker.cpp b/src/checker.cpp index fa04911ac..543763fc3 100644 --- a/src/checker.cpp +++ b/src/checker.cpp @@ -4946,12 +4946,18 @@ gb_internal void check_add_import_decl(CheckerContext *ctx, Ast *decl) { } - if (import_name.len == 0) { + if (is_blank_ident(import_name) && !is_blank_ident(id->import_name.string)) { String invalid_name = id->fullpath; invalid_name = get_invalid_import_name(invalid_name); - error(id->token, "Import name %.*s, is not a valid identifier. Perhaps you want to reference the package by a different name like this: import \"%.*s\" ", LIT(invalid_name), LIT(invalid_name)); - error(token, "Import name, %.*s, cannot be use as an import name as it is not a valid identifier", LIT(id->import_name.string)); + ERROR_BLOCK(); + + if (id->import_name.string.len > 0) { + error(token, "Import name, '%.*s' cannot be use as an import name as it is not a valid identifier", LIT(id->import_name.string)); + } else { + error(id->token, "Import name '%.*s' is not a valid identifier", LIT(invalid_name)); + error_line("\tSuggestion: Rename the directory or explicitly set an import name like this 'import %.*s'", LIT(id->relpath.string)); + } } else { GB_ASSERT(id->import_name.pos.line != 0); id->import_name.string = import_name; From 8e855155fdf4fa7901f59098e8c32719e99c1b63 Mon Sep 17 00:00:00 2001 From: Laytan Laats Date: Sat, 31 Aug 2024 02:38:07 +0200 Subject: [PATCH 2/2] fix bad import --- tests/vendor/all.odin | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/vendor/all.odin b/tests/vendor/all.odin index 1abbc5d7f..ba5628252 100644 --- a/tests/vendor/all.odin +++ b/tests/vendor/all.odin @@ -1,4 +1,4 @@ package tests_vendor -@(require) import "glfw" -@(require) import "lua/5.4" \ No newline at end of file +@(require) import "glfw" +@(require) import _ "lua/5.4"