nim-lang / Nim

Nim is a statically typed compiled systems programming language. It combines successful concepts from mature languages like Python, Ada and Modula. Its design focuses on efficiency, expressiveness, and elegance (in that order of priority).
https://nim-lang.org
Other
16.34k stars 1.47k forks source link

`nim check` reports incorrect errors for nimscript #19440

Closed TheSimpleZ closed 2 years ago

TheSimpleZ commented 2 years ago

Copied over from https://github.com/saem/vscode-nim/issues/72

Example

I'm trying to use a standalone nimscript. The following script:

mode = ScriptMode.Verbose

proc build() =
  echo "building nim... "
  exec "sleep 10"
  echo getCurrentDir()

echo "hello"

Looks like this: image

It's reporting that:

I'd expect it to only report that the build proc is unused.

All errors disappear if I simply call the build proc at the end of the script.

Current Output

Using choosenim devel or choosenim stable and then:

$ nim check nim.nims
hello
Hint: used config file '~/.choosenim/toolchains/nim-1.6.2/config/nim.cfg' [Conf]
Hint: used config file '~/.choosenim/toolchains/nim-1.6.2/config/config.nims' [Conf]
Hint: used config file '~/Documents/monorepo-manager/ci/nim.nims' [Conf]
.........................................................
~/Documents/monorepo-manager/ci/nim.nims(1, 1) Error: undeclared identifier: 'mode'
candidates (edit distance, scope distance); see '--spellSuggest': 
 (1, 2): 'mod' [proc declared in ~/.choosenim/toolchains/nim-1.6.2/lib/system/arithmetics.nim(216, 6)]
 (1, 2): 'mod' [proc declared in ~/.choosenim/toolchains/nim-1.6.2/lib/system/arithmetics.nim(225, 6)]
 (1, 2): 'mod' [proc declared in ~/.choosenim/toolchains/nim-1.6.2/lib/system/arithmetics.nim(226, 6)]
 (1, 2): 'mod' [proc declared in ~/.choosenim/toolchains/nim-1.6.2/lib/system/arithmetics.nim(227, 6)]
 (1, 2): 'mod' [proc declared in ~/.choosenim/toolchains/nim-1.6.2/lib/system/arithmetics.nim(228, 6)]
 (1, 2): 'mod' [proc declared in ~/.choosenim/toolchains/nim-1.6.2/lib/system/arithmetics.nim(394, 6)]
 (1, 2): 'mod' [proc declared in ~/.choosenim/toolchains/nim-1.6.2/lib/system/arithmetics.nim(397, 6)]
 (1, 2): 'mod' [proc declared in ~/.choosenim/toolchains/nim-1.6.2/lib/system/arithmetics.nim(398, 6)]
 (1, 2): 'mod' [proc declared in ~/.choosenim/toolchains/nim-1.6.2/lib/system/arithmetics.nim(399, 6)]
 (1, 2): 'mod' [proc declared in ~/.choosenim/toolchains/nim-1.6.2/lib/system/arithmetics.nim(400, 6)]
 (1, 2): 'move' [proc declared in ~/.choosenim/toolchains/nim-1.6.2/lib/system.nim(286, 6)]
~/Documents/monorepo-manager/ci/nim.nims(1, 1) Error: expression 'mode' has no type (or is ambiguous)
~/Documents/monorepo-manager/ci/nim.nims(1, 1) Error: 'mode' cannot be assigned to
~/Documents/monorepo-manager/ci/nim.nims(5, 3) Error: undeclared identifier: 'exec'
candidates (edit distance, scope distance); see '--spellSuggest': 
 (2, 4): 'dec' [proc declared in ~/.choosenim/toolchains/nim-1.6.2/lib/system/arithmetics.nim(31, 6)]
 (2, 4): 'excl' [func declared in ~/.choosenim/toolchains/nim-1.6.2/lib/system/setops.nim(21, 6)]
 (2, 4): 'excl' [template declared in ~/.choosenim/toolchains/nim-1.6.2/lib/system/setops.nim(30, 10)]
~/Documents/monorepo-manager/ci/nim.nims(5, 8) Error: attempting to call routine: 'exec'
  found 'exec' [unknown declared in ~/Documents/monorepo-manager/ci/nim.nims(5, 3)]
~/Documents/monorepo-manager/ci/nim.nims(5, 8) Error: attempting to call routine: 'exec'
  found 'exec' [unknown declared in ~/Documents/monorepo-manager/ci/nim.nims(5, 3)]
~/Documents/monorepo-manager/ci/nim.nims(5, 8) Error: expression 'exec' cannot be called
~/Documents/monorepo-manager/ci/nim.nims(6, 8) Error: undeclared identifier: 'getCurrentDir'
candidates (edit distance, scope distance); see '--spellSuggest': 
 (8, 5): 'declared' [proc declared in ~/.choosenim/toolchains/nim-1.6.2/lib/system.nim(169, 8)]
 (8, 5): 'getCurrentException' [proc declared in ~/.choosenim/toolchains/nim-1.6.2/lib/system.nim(2407, 8)]
 (8, 5): 'getFrameState' [proc declared in ~/.choosenim/toolchains/nim-1.6.2/lib/system/excpt.nim(88, 6)]
 (8, 5): 'getFreeMem' [proc declared in ~/.choosenim/toolchains/nim-1.6.2/lib/system/alloc.nim(1061, 8)]
~/Documents/monorepo-manager/ci/nim.nims(6, 21) Error: attempting to call routine: 'getCurrentDir'
  found 'getCurrentDir' [unknown declared in ~/Documents/monorepo-manager/ci/nim.nims(6, 8)]
~/Documents/monorepo-manager/ci/nim.nims(6, 21) Error: attempting to call routine: 'getCurrentDir'
  found 'getCurrentDir' [unknown declared in ~/Documents/monorepo-manager/ci/nim.nims(6, 8)]
~/Documents/monorepo-manager/ci/nim.nims(6, 21) Error: expression 'getCurrentDir' cannot be called
~/Documents/monorepo-manager/ci/nim.nims(3, 6) Hint: 'build' is declared but not used [XDeclaredButNotUsed]

Expected Output

Only a warning regarding unused proc. Nothing else. The other methods should be supported in nimscripts according to https://nim-lang.org/docs/nimscript.html

Possible Solution

No idea. I'm quite new to Nim, so I don't know where to start looking.

Additional Information

I'm trying to build a task runner using nimscripts as a base. However, this issue makes it very annoying to use IDEs that report errors since almost every line will be marked red unless called in the root of the module.

$ nim -v             
Nim Compiler Version 1.7.1 [Linux: amd64]
Compiled at 2022-01-05
Copyright (c) 2006-2021 by Andreas Rumpf

git hash: 9df195ef581879cf9e5c3c3154755bd1dba677c6
active boot switches: -d:release

Also tried with the stable channel and got the same result.

ringabout commented 2 years ago

Duplicate of https://github.com/nim-lang/Nim/issues/3858

ringabout commented 2 years ago

update: https://github.com/nim-lang/Nim/pull/19444