-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
#9176 Fix inconsistent behavior of compile time macros when assigned to a constant #9517
Conversation
great!
when defined(posix):
const cmd = "echo foo" # or if you have another idea that makes it clear it's being run at CT, not at RT; but at least it'll catch the empty output bug of https://github.com/nim-lang/Nim/issues/9176
var ret1 = staticExec(cmd)
const tmp = staticExec(cmd)
var ret2 = tmp
doAssert ret1 == ret2 |
Should I make a test for each of the commands? |
meh, at least 1 is a good start |
Interesting diff, I like it. Please add a test case that fails on the old behavior and works correctly on the new behavior. |
I've gone ahead and added a fix for getProjectPath and a test case to verify the fix in tests/system/compiletime.nim. I didn't see anything else that appeared to have this problem in vmopts.nim, but I am very new to the project so I may have missed something. |
maybe update PR title |
Related: #8051 I've noticed that {.compileTime.} pragma doesn't work in many cases while static T return value works. |
This is great! But it has the disadvantage that it allows these compile-time-only procedures to be assigned in a runtime context, previously you would get a "Error: 'staticExec' can only be used in compile-time context" whereas with this PR you won't. Unfortunately I think we need a different solution. |
@dom96 I think this is an acceptable tradeoff, because we have "static" in the name of the proc (ignoring gorge, since that alias is wierd anyways imo). |
Why do we have gorge and gorgeEx anyway? |
|
My question was just why do we have that naming convention in the first place? Why not a single proc that does what gorgeEx does now, but with a more descriptive name? |
Not sure of the heritage, but I like where you're going. #1994 is distantly related if we're talking about tidying up the API before 1.0. |
Because some young fool (@Araq) had fun designing the language and added a single bad joke. |
@@ -3789,12 +3789,10 @@ proc staticRead*(filename: string): string {.magic: "Slurp".} | |||
## | |||
## `slurp <#slurp>`_ is an alias for ``staticRead``. | |||
|
|||
proc gorge*(command: string, input = "", cache = ""): string {. | |||
magic: "StaticExec".} = discard |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removing this magic
here cannot be right.
## This is an alias for `staticExec <#staticExec>`_. | ||
|
||
proc staticExec*(command: string, input = "", cache = ""): string {. | ||
magic: "StaticExec".} = discard |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removing this magic
here cannot be right.
This needs to be solved differently. |
Very simple change marking gorge, gorgeEx and staticExec as
.compileTime.
to fix inconsistent behavior when setting the result of gorgeEx to a constant.