Skip to content

Commit

Permalink
use original module config
Browse files Browse the repository at this point in the history
  • Loading branch information
metagn committed Dec 20, 2024
1 parent 042edaa commit b6e1c7e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
7 changes: 4 additions & 3 deletions compiler/importer.nim
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ proc importForwarded(c: PContext, n: PNode, exceptSet: IntSet; fromMod: PSym; im
for i in 0..n.safeLen-1:
importForwarded(c, n[i], exceptSet, fromMod, importSet)

proc importModuleAs(c: PContext; n: PNode, realModule: PSym, importHidden: bool): PSym =
proc importModuleAs(c: PContext; n: PNode, realModule: PSym, importHidden, trackUnusedImport: bool): PSym =
result = realModule
template createModuleAliasImpl(ident): untyped =
createModuleAlias(realModule, c.idgen, ident, n.info, c.config.options)
Expand All @@ -248,7 +248,7 @@ 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
if warnUnusedImportX in c.config.notes:
if trackUnusedImport:
c.unusedImports.add((result, result.info))
c.importModuleMap[result.id] = realModule.id
c.importModuleLookup.mgetOrPut(result.name.id, @[]).addUnique realModule.id
Expand Down Expand Up @@ -290,10 +290,11 @@ proc myImportModule(c: PContext, n: var PNode, importStmtResult: PNode): PSym =
toFullPath(c.config, c.graph.importStack[i+1])
c.recursiveDep = err

let trackUnusedImport = warnUnusedImportX in c.config.notes
var realModule: PSym
discard pushOptionEntry(c)
realModule = c.graph.importModuleCallback(c.graph, c.module, f)
result = importModuleAs(c, n, realModule, transf.importHidden)
result = importModuleAs(c, n, realModule, transf.importHidden, trackUnusedImport)
popOptionEntry(c)

#echo "set back to ", L
Expand Down
9 changes: 8 additions & 1 deletion tests/import/tpushunusedwarning.nim
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
discard """
action: compile
matrix: "--hints:off"
nimoutFull: true
nimout: '''
'''
"""

# issue #24552

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

0 comments on commit b6e1c7e

Please sign in to comment.