summary refs log tree commit diff stats
path: root/compiler
diff options
context:
space:
mode:
authorAndreas Rumpf <rumpf_a@web.de>2019-07-18 18:16:25 +0200
committerAndreas Rumpf <rumpf_a@web.de>2019-07-18 18:16:25 +0200
commit9852cf804b09710837c849bdfda2be499e702a05 (patch)
tree6394c0dbbd3963ab6655a9432372ffbb51111b68 /compiler
parent4137a4dbf386f19b0ce4f5de5b0a8ab05a3b2b8b (diff)
downloadNim-9852cf804b09710837c849bdfda2be499e702a05.tar.gz
warn about unused imports; fixes an 'export' regression [nobackport]
Diffstat (limited to 'compiler')
-rw-r--r--compiler/lineinfos.nim8
-rw-r--r--compiler/sem.nim2
-rw-r--r--compiler/semexprs.nim6
3 files changed, 9 insertions, 7 deletions
diff --git a/compiler/lineinfos.nim b/compiler/lineinfos.nim
index a7019a50f..42d33de7d 100644
--- a/compiler/lineinfos.nim
+++ b/compiler/lineinfos.nim
@@ -33,12 +33,13 @@ type
     warnFieldXNotSupported, warnCommentXIgnored,
     warnTypelessParam,
     warnUseBase, warnWriteToForeignHeap, warnUnsafeCode,
+    warnUnusedImportX,
     warnEachIdentIsTuple,
     warnProveInit, warnProveField, warnProveIndex, warnGcUnsafe, warnGcUnsafe2,
     warnUninit, warnGcMem, warnDestructor, warnLockLevel, warnResultShadowed,
     warnInconsistentSpacing, warnCaseTransition, warnUser,
     hintSuccess, hintSuccessX, hintCC,
-    hintLineTooLong, hintXDeclaredButNotUsed, hintUnusedModuleX,
+    hintLineTooLong, hintXDeclaredButNotUsed,
     hintConvToBaseNotNeeded,
     hintConvFromXtoItselfNotNeeded, hintExprAlwaysX, hintQuitCalled,
     hintProcessing, hintCodeBegin, hintCodeEnd, hintConf, hintPath,
@@ -79,6 +80,7 @@ const
     warnUseBase: "use {.base.} for base methods; baseless methods are deprecated",
     warnWriteToForeignHeap: "write to foreign heap",
     warnUnsafeCode: "unsafe code: '$1'",
+    warnUnusedImportX: "imported and not used: '$1'",
     warnEachIdentIsTuple: "each identifier is a tuple",
     warnProveInit: "Cannot prove that '$1' is initialized. This will become a compile time error in the future.",
     warnProveField: "cannot prove that field '$1' is accessible",
@@ -98,7 +100,6 @@ const
     hintCC: "CC: \'$1\'", # unused
     hintLineTooLong: "line too long",
     hintXDeclaredButNotUsed: "'$1' is declared but not used",
-    hintUnusedModuleX: "unused module: '$1'",
     hintConvToBaseNotNeeded: "conversion to base object is not needed",
     hintConvFromXtoItselfNotNeeded: "conversion from $1 to itself is pointless",
     hintExprAlwaysX: "expression evaluates always to '$1'",
@@ -135,6 +136,7 @@ const
     "LanguageXNotSupported", "FieldXNotSupported",
     "CommentXIgnored",
     "TypelessParam", "UseBase", "WriteToForeignHeap",
+    "UnusedModule",
     "UnsafeCode", "EachIdentIsTuple",
     "ProveInit", "ProveField", "ProveIndex", "GcUnsafe", "GcUnsafe2", "Uninit",
     "GcMem", "Destructor", "LockLevel", "ResultShadowed",
@@ -142,7 +144,7 @@ const
 
   HintsToStr* = [
     "Success", "SuccessX", "CC", "LineTooLong",
-    "XDeclaredButNotUsed", "UnusedModule",
+    "XDeclaredButNotUsed",
     "ConvToBaseNotNeeded", "ConvFromXtoItselfNotNeeded",
     "ExprAlwaysX", "QuitCalled", "Processing", "CodeBegin", "CodeEnd", "Conf",
     "Path", "CondTrue", "CondFalse", "Name", "Pattern", "Exec", "Link", "Dependency",
diff --git a/compiler/sem.nim b/compiler/sem.nim
index ce2c9c5ad..39ffeeb4d 100644
--- a/compiler/sem.nim
+++ b/compiler/sem.nim
@@ -620,7 +620,7 @@ proc myProcess(context: PPassContext, n: PNode): PNode =
 
 proc reportUnusedModules(c: PContext) =
   for i in 0..high(c.unusedImports):
-    message(c.config, c.unusedImports[i][1], hintUnusedModuleX, c.unusedImports[i][0].name.s)
+    message(c.config, c.unusedImports[i][1], warnUnusedImportX, c.unusedImports[i][0].name.s)
 
 proc myClose(graph: ModuleGraph; context: PPassContext, n: PNode): PNode =
   var c = PContext(context)
diff --git a/compiler/semexprs.nim b/compiler/semexprs.nim
index 00f4620af..733df2c40 100644
--- a/compiler/semexprs.nim
+++ b/compiler/semexprs.nim
@@ -2450,7 +2450,7 @@ proc semExportExcept(c: PContext, n: PNode): PNode =
   var s = initTabIter(i, exported.tab)
   while s != nil:
     if s.kind in ExportableSymKinds+{skModule} and
-       s.name.id notin exceptSet:
+       s.name.id notin exceptSet and sfError notin s.flags:
       strTableAdd(c.module.tab, s)
       result.add newSymNode(s, n.info)
       markUsed(c, n.info, s, c.graph.usageSym)
@@ -2480,10 +2480,10 @@ proc semExport(c: PContext, n: PNode): PNode =
         if s.kind == skEnumField:
           localError(c.config, a.info, errGenerated, "cannot export: " & renderTree(a) &
             "; enum field cannot be exported individually")
-        if s.kind in ExportableSymKinds+{skModule}:
+        if s.kind in ExportableSymKinds+{skModule} and sfError notin s.flags:
           result.add(newSymNode(s, a.info))
           strTableAdd(c.module.tab, s)
-        markUsed(c, n.info, s, c.graph.usageSym)
+          markUsed(c, n.info, s, c.graph.usageSym)
         s = nextOverloadIter(o, c, a)
 
 proc semTupleConstr(c: PContext, n: PNode, flags: TExprFlags): PNode =