even lighter version of #17938: fix most issues with UnusedImport, XDeclaredButNotUsed, etc; fix #17511, #17510, #14246 (without realModule) (#18362)
* {.used: symbol}
* add tests
* fix tests with --import
* --import works without giving spurious unused warnings
* new warning warnDuplicateModuleImport for `import foo; import foo`
* fix test, add resolveModuleAlias, use proper line info for module aliases
* fix spurious warnings
* fix deprecation msg for deprecated modules even with `import foo as bar`
* disable a test for i386 pending sorting XDeclaredButNotUsed errors
* UnusedImport now works with re-exported symbols
* fix typo [skip ci]
* ic support
* add genPNode to allow writing PNode-based compiler code similarly to `genAst`
* fix DuplicateModuleImport warning
* adjust test
* fixup
* fixup
* fixup
* fix after rebase
* fix for IC
* keep the proc inline, move the const out
* [skip ci] fix changelog
* experiment: remove calls to resolveModuleAlias
* followup
* fixup
* fix tests/modules/tselfimport.nim
* workaround tests/deprecated/tmodule1.nim
* fix properly
* simplify
This commit is contained in:
parent
39fbf3c84b
commit
b8f761b7e2
13 changed files with 155 additions and 60 deletions
|
|
@ -58,8 +58,8 @@ proc considerQuotedIdent*(c: PContext; n: PNode, origin: PNode = nil): PIdent =
|
|||
template addSym*(scope: PScope, s: PSym) =
|
||||
strTableAdd(scope.symbols, s)
|
||||
|
||||
proc addUniqueSym*(scope: PScope, s: PSym): PSym =
|
||||
result = strTableInclReportConflict(scope.symbols, s)
|
||||
proc addUniqueSym*(scope: PScope, s: PSym, onConflictKeepOld: bool): PSym =
|
||||
result = strTableInclReportConflict(scope.symbols, s, onConflictKeepOld)
|
||||
|
||||
proc openScope*(c: PContext): PScope {.discardable.} =
|
||||
result = PScope(parent: c.currentScope,
|
||||
|
|
@ -288,19 +288,23 @@ proc ensureNoMissingOrUnusedSymbols(c: PContext; scope: PScope) =
|
|||
message(c.config, s.info, hintXDeclaredButNotUsed, s.name.s)
|
||||
|
||||
proc wrongRedefinition*(c: PContext; info: TLineInfo, s: string;
|
||||
conflictsWith: TLineInfo) =
|
||||
conflictsWith: TLineInfo, note = errGenerated) =
|
||||
## Emit a redefinition error if in non-interactive mode
|
||||
if c.config.cmd != cmdInteractive:
|
||||
localError(c.config, info,
|
||||
localError(c.config, info, note,
|
||||
"redefinition of '$1'; previous declaration here: $2" %
|
||||
[s, c.config $ conflictsWith])
|
||||
|
||||
# xxx pending bootstrap >= 1.4, replace all those overloads with a single one:
|
||||
# proc addDecl*(c: PContext, sym: PSym, info = sym.info, scope = c.currentScope) {.inline.} =
|
||||
proc addDeclAt*(c: PContext; scope: PScope, sym: PSym, info: TLineInfo) =
|
||||
let conflict = scope.addUniqueSym(sym)
|
||||
let conflict = scope.addUniqueSym(sym, onConflictKeepOld = true)
|
||||
if conflict != nil:
|
||||
wrongRedefinition(c, info, sym.name.s, conflict.info)
|
||||
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)
|
||||
|
||||
proc addDeclAt*(c: PContext; scope: PScope, sym: PSym) {.inline.} =
|
||||
addDeclAt(c, scope, sym, sym.info)
|
||||
|
|
@ -312,7 +316,7 @@ proc addDecl*(c: PContext, sym: PSym) {.inline.} =
|
|||
addDeclAt(c, c.currentScope, sym)
|
||||
|
||||
proc addPrelimDecl*(c: PContext, sym: PSym) =
|
||||
discard c.currentScope.addUniqueSym(sym)
|
||||
discard c.currentScope.addUniqueSym(sym, onConflictKeepOld = false)
|
||||
|
||||
from ic / ic import addHidden
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue