Skip to content

Commit

Permalink
check if unused import warning is enabled before adding import to stack
Browse files Browse the repository at this point in the history
  • Loading branch information
metagn committed Dec 20, 2024
1 parent ce4304c commit 042edaa
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
3 changes: 2 additions & 1 deletion compiler/importer.nim
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,8 @@ proc importModuleAs(c: PContext; n: PNode, realModule: PSym, importHidden: bool)
result.options.incl optImportHidden
let moduleIdent = if n.kind in {nkInfix, nkImportAs}: n[^1] else: n
result.info = moduleIdent.info
c.unusedImports.add((result, result.info))
if warnUnusedImportX in c.config.notes:
c.unusedImports.add((result, result.info))
c.importModuleMap[result.id] = realModule.id
c.importModuleLookup.mgetOrPut(result.name.id, @[]).addUnique realModule.id

Expand Down
9 changes: 9 additions & 0 deletions tests/import/tpushunusedwarning.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# issue #24552

{.warningAsError[UnusedImport]: on.}
{.push warning[UnusedImport]: off.}
import tables
{.pop.}

proc test*(a: float): float =
a

0 comments on commit 042edaa

Please sign in to comment.