diff options
author | 2023-04-13 17:41:07 -0700 | |
---|---|---|
committer | 2023-04-13 17:41:07 -0700 | |
commit | 476ab240818aa42071db628cd1a47260968dd556 (patch) | |
tree | 8db20b68f64369a347b00b1642b2b36b75bddb67 | |
parent | 8a2545a17298514e0830136cd6464a429e6fa5ba (diff) | |
download | bun-476ab240818aa42071db628cd1a47260968dd556.tar.gz bun-476ab240818aa42071db628cd1a47260968dd556.tar.zst bun-476ab240818aa42071db628cd1a47260968dd556.zip |
fix ambiguous import (#2654)
* check all files before
* better error/warning
* update todo
-rw-r--r-- | src/bundler/bundle_v2.zig | 38 |
1 files changed, 26 insertions, 12 deletions
diff --git a/src/bundler/bundle_v2.zig b/src/bundler/bundle_v2.zig index bebfddae3..304621e50 100644 --- a/src/bundler/bundle_v2.zig +++ b/src/bundler/bundle_v2.zig @@ -7457,17 +7457,31 @@ const LinkerContext = struct { const r = lex.rangeOfIdentifier(source, named_import.alias_loc orelse Logger.Loc{}); - // if (result.name_loc.start != 0) - // TODO: better error - c.log.addRangeErrorFmt( - source, - r, - c.allocator, - "Ambiguous import: {s}", - .{ - named_import.alias.?, - }, - ) catch unreachable; + // TODO: log locations of the ambiguous exports + + const symbol: *Symbol = c.graph.symbols.get(import_ref).?; + if (symbol.import_item_status == .generated) { + symbol.import_item_status = .missing; + c.log.addRangeWarningFmt( + source, + r, + c.allocator, + "Import \"{s}\" will always be undefined because there are multiple matching exports", + .{ + named_import.alias.?, + }, + ) catch unreachable; + } else { + c.log.addRangeErrorFmt( + source, + r, + c.allocator, + "Ambiguous import \"{s}\" has multiple matching exports", + .{ + named_import.alias.?, + }, + ) catch unreachable; + } }, .ignore => {}, } @@ -7527,7 +7541,7 @@ const LinkerContext = struct { continue; // This export star is shadowed if any file in the stack has a matching real named export - for (this.source_index_stack.items[stack_end_pos..]) |prev| { + for (this.source_index_stack.items[0..stack_end_pos]) |prev| { if (this.named_exports[prev].contains(alias)) { continue :next_export; } |