summary refs log tree commit diff stats
path: root/compiler/lookups.nim
diff options
context:
space:
mode:
authorTimothee Cour <timothee.cour2@gmail.com>2021-06-27 11:39:16 -0700
committerGitHub <noreply@github.com>2021-06-27 20:39:16 +0200
commit0b7361e938134305d6893ee2876b5fc8f9ba419b (patch)
tree0de77b56c54acfac597823b40706384e235595f7 /compiler/lookups.nim
parent1b9b8060075efab82912dc33ba64e671d102b999 (diff)
downloadNim-0b7361e938134305d6893ee2876b5fc8f9ba419b.tar.gz
followup #18362: make `UnusedImport` work robustly (#18366)
* warnDuplicateModuleImport => hintDuplicateModuleImport
* improve DuplicateModuleImport msg, add test
Diffstat (limited to 'compiler/lookups.nim')
-rw-r--r--compiler/lookups.nim12
1 files changed, 8 insertions, 4 deletions
diff --git a/compiler/lookups.nim b/compiler/lookups.nim
index 0e057a79a..9b878dd4b 100644
--- a/compiler/lookups.nim
+++ b/compiler/lookups.nim
@@ -300,11 +300,15 @@ proc wrongRedefinition*(c: PContext; info: TLineInfo, s: string;
 proc addDeclAt*(c: PContext; scope: PScope, sym: PSym, info: TLineInfo) =
   let conflict = scope.addUniqueSym(sym, onConflictKeepOld = true)
   if conflict != nil:
-    var note = errGenerated
     if sym.kind == skModule and conflict.kind == skModule and sym.owner == conflict.owner:
-      # import foo; import foo
-      note = warnDuplicateModuleImport
-    wrongRedefinition(c, info, sym.name.s, conflict.info, note)
+      # e.g.: import foo; import foo
+      # xxx we could refine this by issuing a different hint for the case
+      # where a duplicate import happens inside an include.
+      localError(c.config, info, hintDuplicateModuleImport,
+        "duplicate import of '$1'; previous import here: $2" %
+        [sym.name.s, c.config $ conflict.info])
+    else:
+      wrongRedefinition(c, info, sym.name.s, conflict.info, errGenerated)
 
 proc addDeclAt*(c: PContext; scope: PScope, sym: PSym) {.inline.} =
   addDeclAt(c, scope, sym, sym.info)