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.41k stars 1.47k forks source link

compiler flag `--hintAsError[XDeclaredButNotUsed]:on` causes unavoidable error in `fatal.nim` that `goToBasedException` is never used #20149

Closed PhilippMDoerner closed 2 years ago

PhilippMDoerner commented 2 years ago

I tried compiling code with the --hintAsError[XDeclaredButNotUsed]:on flag turned on. When doing so, the compiler will always throw the following exception from fatal.nim. This makes the flag unuseable.

Example

# Add this to nimble file
task release, "Blub":
  --hintAsError[XDeclaredButNotUsed]:on #Can't be used because systems.nim itself has screwy stuff
  --outdir:"."
  setCommand "c", "playfile.nim"

# playfile.nim
let x = 5
echo x

# in terminal
nimble release

Current Output

/home/philipp/.choosenim/toolchains/nim-#devel/lib/system/fatal.nim(13, 9) Error: 'gotoBasedExceptions' is declared but not used [XDeclaredButNotUsed]

The line this is talking about is the second one in the following code-block

when defined(nimHasExceptionsQuery):
  const gotoBasedExceptions = compileOption("exceptions", "goto") # <-- This is line 13
else:
  const gotoBasedExceptions = false

Expected Output

5

Possible Solution

I don't have a direct solution, but I see multiple ways: 1) Make it so the flag does not apply to foreign packages, including systems.nim! (!) This is my preferred solution (!) 2) The usage of gotoBasedExceptions appears to be mostly within when statements. Could it be that for the compiler only being used in when statements does not count to escape this check? Maybe this could be changed.

Additional Information

I do not know when this was introduced, I only started playing around with this around nim 1.6.6 and tested again with nim devel (1.7.1) and git head (installed via choosenim #head).

Nim Compiler Version 1.7.1 [Linux: amd64]
Compiled at 2022-07-17
Copyright (c) 2006-2022 by Andreas Rumpf

git hash: 0d8bec695606a65c5916d0da7fcb0a976a4e1f7b
active boot switches: -d:release
PhilippMDoerner commented 2 years ago

I have come to notice that the PR #20151 may fix this issue, looking forward to it!

PhilippMDoerner commented 2 years ago

That PR fixes this issue and in fact another, similar one, that I had that made --warningAsError[UnusedImport]:on unuseable. See the comment in the PR for further infos