Open demotomohiro opened 1 year ago
this also works:
import macrocache
const ctableM = CacheTable"ctable"
proc getString(): string =
for key, val in ctableM:
result = key
proc test() {.compileTime.} =
ctableM["Key In CacheTable"] = nil
var a = getString()
echo a
static:
test()
Indeed getString
being called inside a proc
with both tagged as compileTime
causes it to be run off the rip. This kind of makes sense if you assume that test
is going to be parsed in full before the VM starts evaluating the instructions, but it's probably not preferable. To be clear, this is happening because getString
is running before test
's body
Edit: It's running before test
is even called actually.
I think this has something to do with the inner proc
having a return value, because the order is correct when there is no return type specified:
proc l1_1(): int {.compileTime.} =
echo "l1_1"
proc test() {.compileTime.} =
echo "test"
discard l1_1()
proc l3(): int {.compileTime.} =
echo "l3"
proc l2() {.compiletime.} =
echo "l2"
discard l3()
proc test2() {. compileTime .} =
echo "test2"
l2()
static:
echo "static"
test()
test2()
Description
I added a value to
CacheTable
in macrocache module and tried to read a key from it in compileTime proc, but didn't get a value as if it is emtpy.Run following code with
nim c testmc.nim
:testmc.nim
Nim Version
Current Output
Expected Output
Possible Solution
No response
Additional Information
Following code works:
So it looks like calling compileTime procedure from compileTime procedure causing this bug.