Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
monkey-w1n5t0n opened this issue Mar 21, 2021 · 3 comments
Open
Labels

Comments

@monkey-w1n5t0n
Copy link

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 timotheecour added Invalid Code Acceptance Everything related to compiler not complaining about invalid code Easy labels Mar 21, 2021
@timotheecour
Copy link
Member

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

  • in commands.nim, the "out" flag should given an error if main project is a nims file or in other cases too, eg for commands where out doesnt' make sense (eg: nim danger + a few others)

@monkey-w1n5t0n
Copy link
Author

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 timotheecour removed the Invalid Code Acceptance Everything related to compiler not complaining about invalid code label Mar 22, 2021
@timotheecour
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants