Nim icon indicating copy to clipboard operation
Nim copied to clipboard

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

Open PhilippMDoerner opened this issue 1 year ago • 2 comments

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 avatar Aug 03 '22 21:08 PhilippMDoerner

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

PhilippMDoerner avatar Aug 04 '22 05:08 PhilippMDoerner

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

PhilippMDoerner avatar Aug 04 '22 07:08 PhilippMDoerner