diff options
| author | Laytan <laytanlaats@hotmail.com> | 2024-08-31 02:44:16 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-08-31 02:44:16 +0200 |
| commit | 584e8859bfa33f0a617692d7b58b1a0fd234245d (patch) | |
| tree | 20ea902a9fa4f02240b621ba101107b3566d5e00 /src/checker.cpp | |
| parent | bfedcd70355c4571f881450419022d85032f5fda (diff) | |
| parent | 8e855155fdf4fa7901f59098e8c32719e99c1b63 (diff) | |
Merge pull request #4168 from laytan/fix-bad-import-name-errors
fix some issues with the "bad import name" errors
Diffstat (limited to 'src/checker.cpp')
| -rw-r--r-- | src/checker.cpp | 12 |
1 files 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 <new_name> \"%.*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 <new_name> %.*s'", LIT(id->relpath.string)); + } } else { GB_ASSERT(id->import_name.pos.line != 0); id->import_name.string = import_name; |