From 86c1aed20d3900b2a5df905a821bf13a074dc102 Mon Sep 17 00:00:00 2001 From: Kelly Wilson Date: Sun, 25 Apr 2021 23:26:12 -0600 Subject: [PATCH 1/2] Fix for issue 820 (import name is not an identifier) --- src/checker.cpp | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/checker.cpp b/src/checker.cpp index f386d6da7..42462c0fa 100644 --- a/src/checker.cpp +++ b/src/checker.cpp @@ -3747,6 +3747,19 @@ Array find_import_path(Checker *c, AstPackage *start, AstPackage return empty_path; } #endif + +String get_invalid_import_name(String input) { + isize slash = 0; + for (isize i = input.len-1; i >= 0; i--) { + if (input[i] == '/' || input[i] == '\\') { + break; + } + slash = i; + } + input = substring(input, slash, input.len); + return input; +} + void check_add_import_decl(CheckerContext *ctx, Ast *decl) { if (decl->state_flags & StateFlag_BeenHandled) return; decl->state_flags |= StateFlag_BeenHandled; @@ -3804,7 +3817,14 @@ void check_add_import_decl(CheckerContext *ctx, Ast *decl) { if (id->is_using) { // TODO(bill): Should this be a warning? } else { - error(token, "Import name, %.*s, cannot be use as an import name as it is not a valid identifier", LIT(id->import_name.string)); + if (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)); + } else { + 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 { GB_ASSERT(id->import_name.pos.line != 0); From aa846d0ea5f40361cc4ada2213c4659fe1b59580 Mon Sep 17 00:00:00 2001 From: gingerBill Date: Mon, 26 Apr 2021 11:46:26 +0100 Subject: [PATCH 2/2] Fix `union #maybe` comparison against `nil` -llvm-api --- src/llvm_backend.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/llvm_backend.cpp b/src/llvm_backend.cpp index 0d27b9c6f..a92f53774 100644 --- a/src/llvm_backend.cpp +++ b/src/llvm_backend.cpp @@ -10118,6 +10118,9 @@ lbValue lb_emit_comp_against_nil(lbProcedure *p, TokenKind op_kind, lbValue x) { } else if (op_kind == Token_NotEq) { return lb_const_bool(p->module, t_llvm_bool, false); } + } else if (is_type_union_maybe_pointer(t)) { + lbValue tag = lb_emit_transmute(p, x, t_rawptr); + return lb_emit_comp_against_nil(p, op_kind, tag); } else { lbValue tag = lb_emit_union_tag_value(p, x); return lb_emit_comp(p, op_kind, tag, lb_zero(p->module, tag.type));