While investigating this issue in nimlsp I noticed that if nimsuggest is compiled without -d:danger it will crash with a RangeError:
[peter /tmp ] $ cat test.nim
type MyType = object
x: int
var y: MyType
y.
[peter /tmp ] $ ./Nim/nimsuggest/nimsuggest --debug --stdin test.nim
Hint: used config file '/tmp/Nim/config/nim.cfg' [Conf]
Hint: used config file '/tmp/Nim/config/config.nims' [Conf]
usage: sug|con|def|use|dus|chk|mod|highlight|outline|known file.nim[;dirtyfile.nim]:line:col
type 'quit' to quit
type 'debug' to toggle debug mode on/off
type 'terse' to toggle terse mode on/off
> sug test.nim 5 3
/tmp/Nim/nimsuggest/nimsuggest.nim(639) nimsuggest
/tmp/Nim/nimsuggest/nimsuggest.nim(636) handleCmdLine
/home/peter/.choosenim/toolchains/nim-0.20.2/compiler/cmdlinehelper.nim(92) loadConfigsAndRunMainCommand
/tmp/Nim/nimsuggest/nimsuggest.nim(545) mainCommand
/tmp/Nim/nimsuggest/nimsuggest.nim(493) mainThread
/tmp/Nim/nimsuggest/nimsuggest.nim(459) execCmd
/tmp/Nim/nimsuggest/nimsuggest.nim(213) execute
/tmp/Nim/nimsuggest/nimsuggest.nim(197) executeNoHooks
/home/peter/.choosenim/toolchains/nim-0.20.2/compiler/modules.nim(147) compileProject
/home/peter/.choosenim/toolchains/nim-0.20.2/compiler/modules.nim(95) compileModule
/home/peter/.choosenim/toolchains/nim-0.20.2/compiler/passes.nim(206) processModule
/home/peter/.choosenim/toolchains/nim-0.20.2/compiler/passes.nim(78) closePasses
/home/peter/.choosenim/toolchains/nim-0.20.2/compiler/sem.nim(624) myClose
/home/peter/.choosenim/toolchains/nim-0.20.2/compiler/suggest.nim(628) suggestSentinel
/home/peter/.choosenim/toolchains/nim-0.20.2/compiler/msgs.nim(99) newLineInfo
/home/peter/.choosenim/toolchains/nim-0.20.2/lib/system/fatal.nim(48) sysFatal
Error: unhandled exception: value out of range: -1 [RangeError]
[peter /tmp ] $ cd Nim/nimsuggest
[peter /tmp/Nim/nimsuggest (devel) ✓ ] $ nimble build -d:danger
Warning: The .nimble file for this project could make use of additional features, if converted into the new NimScript format.
... For more details see:https://github.com/nim-lang/nimble#creating-packages
Verifying dependencies for nimsuggest@0.1.0
Info: Dependency on compiler@#head already satisfied
Warning: Package 'compiler' has an incorrect structure. It should contain a single directory hierarchy for source files, named 'compiler', but file 'crashtester.nim' is in a directory named 'nimsuggest' instead. This will be an error in the future.
Hint: If 'nimsuggest' contains source files for building 'compiler', rename it to 'compiler'. Otherwise, prevent its installation by adding `skipDirs = @["nimsuggest"]` to the .nimble file.
Verifying dependencies for compiler@#head
Building nimsuggest/nimsuggest using c backend
[peter /tmp/Nim/nimsuggest (devel) ✓ ] $ cd ../..
[peter /tmp ] $ ./Nim/nimsuggest/nimsuggest --debug --stdin test.nim
Hint: used config file '/tmp/Nim/config/nim.cfg' [Conf]
Hint: used config file '/tmp/Nim/config/config.nims' [Conf]
usage: sug|con|def|use|dus|chk|mod|highlight|outline|known file.nim[;dirtyfile.nim]:line:col
type 'quit' to quit
type 'debug' to toggle debug mode on/off
type 'terse' to toggle terse mode on/off
> sug test.nim 5 3
sug skVar test.y MyType /tmp/test.nim 4 4 "" 0 None
sug skType test.MyType MyType /tmp/test.nim 1 5 "" 0 None
sug skProc system.inc proc (x: var T: Ordinal or uint or uint64, y: int){.noSideEffect.} /tmp/Nim/lib/system.nim 937 5 "Increments the ordinal ``x`` by ``y``.\x0A\x0AIf such a value does not exist, ``OverflowError`` is raised or a compile\x0Atime error occurs. This is a short notation for: ``x = succ(x, y)``.\x0A\x0A.. code-block:: Nim\x0A var i = 2\x0A inc(i) # i <- 3\x0A inc(i, 3) # i <- 6" 0 None
sug skProc system.add proc (x: var string, y: string){.noSideEffect.} /tmp/Nim/lib/system.nim 1900 5 "Concatenates `x` and `y` in place.\x0A\x0A.. code-block:: Nim\x0A var tmp = \"\"\x0A tmp.add(\"ab\")\x0A tmp.add(\"cd\")\x0A assert(tmp == \"abcd\")" 0 None
sug skEnumField system.bool.true bool /tmp/Nim/lib/system.nim 45 15 "" 0 None
sug skProc system.len proc (x: string): int{.noSideEffect.} /tmp/Nim/lib/system.nim 1037 5 "Returns the length of a string.\x0A\x0A.. code-block:: Nim\x0A var str = \"Hello world!\"\x0A echo len(str) # => 12" 0 None
sug skEnumField system.bool.false bool /tmp/Nim/lib/system.nim 45 4 "" 0 None
sug skConst system.off bool /tmp/Nim/lib/system.nim 58 2 "" 0 None
sug skProc system.ord proc (x: T: Ordinal or enum): int{.noSideEffect.} /tmp/Nim/lib/system.nim 1117 5 "Returns the internal `int` value of an ordinal value ``x``.\x0A\x0A.. code-block:: Nim\x0A echo ord(\'A\') # => 65\x0A echo ord(\'a\') # => 97" 0 None
Had a look at the code and it seems like it is a uint conversion that fails, the recent change that uint can't convert -1 to the highest possible uint is likely the culprit.
While investigating this issue in
nimlsp
I noticed that ifnimsuggest
is compiled without-d:danger
it will crash with aRangeError
: