Files
Nim/tests/tools/tunused_imports.nim
Jake Leahy 69e0cdb6c0 Fix line info for import (#24523)
Refs #24158


Fixes the line info of the module symbol (cases like `import as` and
grouped imports had wrong line info). Since that symbol's line info is
now used for the warnings, there isn't a separate line info stored for
`unusedImports`

Examples of fixed cases
```nim
import strutils as test #[
                ^ before
                   ^ after ]#

# This case was fixed by #24158, but only for unused imports
import std/[strutils, strutils] #[
        ^ before
                      ^ after ]#

from strutils import split #[
^ before 
     ^ after ]#
```
2024-12-11 20:55:55 +01:00

44 lines
1.0 KiB
Nim

discard """
cmd: '''nim c --hint:Processing:off $file'''
nimout: '''
tunused_imports.nim(15, 10) Warning: BEGIN [User]
tunused_imports.nim(43, 10) Warning: END [User]
tunused_imports.nim(38, 8) Warning: imported and not used: 'strutils' [UnusedImport]
tunused_imports.nim(39, 13) Warning: imported and not used: 'strtabs' [UnusedImport]
tunused_imports.nim(39, 22) Warning: imported and not used: 'cstrutils' [UnusedImport]
tunused_imports.nim(40, 12) Warning: imported and not used: 'macrocache' [UnusedImport]
tunused_imports.nim(41, 25) Warning: imported and not used: 'basics' [UnusedImport]
'''
action: "compile"
"""
{.warning: "BEGIN".}
# bug #12885
import tables, second
template test(key: int): untyped =
`[]`(dataEx, key)
echo test(1)
import net, dontmentionme
echo AF_UNIX
import macros
# bug #11809
macro bar(): untyped =
template baz() = discard
result = getAst(baz())
bar()
import strutils
import std/[strtabs, cstrutils]
import std/macrocache
import std/strbasics as basics
{.warning: "END".}