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

Adding `--out:exe_name` flag to a bare nimscript crashes compilation #17438

Open monkey-w1n5t0n opened 3 years ago

monkey-w1n5t0n commented 3 years ago

Compiling with nim c --out:hello_world main.nim works fine, but adding the --out:hello_world flag to main.nims crashes compilation.

Example

Contents of a recreate.sh shell script:

mkdir recreate_bug && cd recreate_bug

# This works
echo "echo(\"hello world\")" > main.nim
echo "--run" > main.nims
nim c main.nim 

# This also works
nim c --out:hello_world main.nim 

# This doesn't work :(
echo "--out:hello_world" >> main.nims
nim c main.nim

Current Output

(comments added for clarity)

~/code/bug $ ./recreate.sh
## First
Hint: used config file 'C:\Program Files\Nim\nim-1.4.4\config\nim.cfg' [Conf]
Hint: used config file 'C:\Program Files\Nim\nim-1.4.4\config\config.nims' [Conf]
....
Hint:  [Link]
Hint: 29919 lines; 0.514s; 31.738MiB peakmem; Debug build; proj: C:\Users\Scored\code\bug\recreate_bug\main.nim; out: C:\Users\Scored\code\bug\recreate_bug\main.exe [SuccessX]
Hint: C:\Users\Scored\code\bug\recreate_bug\main.exe  [Exec]
hello world

## Second
Hint: used config file 'C:\Program Files\Nim\nim-1.4.4\config\nim.cfg' [Conf]
Hint: used config file 'C:\Program Files\Nim\nim-1.4.4\config\config.nims' [Conf]
....
Hint:  [Link]
Hint: 29919 lines; 0.506s; 31.785MiB peakmem; Debug build; proj: C:\Users\Scored\code\bug\recreate_bug\main.nim; out: C:\Users\Scored\code\bug\recreate_bug\hello_world [SuccessX]
Hint: C:\Users\Scored\code\bug\recreate_bug\hello_world  [Exec]
hello world

## Third
Hint: used config file 'C:\Program Files\Nim\nim-1.4.4\config\nim.cfg' [Conf]
Hint: used config file 'C:\Program Files\Nim\nim-1.4.4\config\config.nims' [Conf]
fatal.nim(49)            sysFatal
Error: unhandled exception: index out of bounds, the container is empty [IndexDefect]

Expected Output

## Third should also produce an executable named hello_world and run it to print hello world.

Additional Information

Windows 10 Home (using git-bash to run the script)

$ nim -v
Nim Compiler Version 1.4.4 [Windows: amd64]
Compiled at 2021-02-23
Copyright (c) 2006-2020 by Andreas Rumpf

active boot switches: -d:release
timotheecour commented 3 years ago

@lm-w1n5t0n PR welcome, it shouldn't be too hard:

monkey-w1n5t0n commented 3 years ago

Would love to contribute but I've only just started learning Nim, so it will take a while to build up to that point.

Just to clarify, this is not supposed to work? I thought that the nimscript file could store any of the flags that can be used when calling the compiler directly, and I don't see why specifying the output binary location should be an exception.

timotheecour commented 3 years ago

I misread, i thought you were calling nim e --out:foo main.nims which should give a CT error since no binary is produced in this case

indeed this should work:

nim c main with main.nims containing --out:foo

you can build a debug version of compiler as follows https://nim-lang.github.io/Nim/intern.html#rebuilding-the-compiler and get a stacktrace, as a starting point

tocariimaa commented 1 month ago

Seems that the bug was fixed, I can't reproduce it on 2.0.8.