Description
When using a block to initialize a const at compile time, I am seeing variables keep values from the previous scope / not be re-initialized as expected.
Run with nim c -r test.nim
const test = block:
for i in 1 .. 5:
var arr: array[3, int]
var val: int
echo arr, " ", val
for j in 0 ..< len(arr):
arr[j] = i
val = i
0
Current Output
[0, 0, 0] 0
[1, 1, 1] 1
[2, 2, 2] 2
[3, 3, 3] 3
[4, 4, 4] 4
Expected Output
[0, 0, 0] 0
[0, 0, 0] 0
[0, 0, 0] 0
[0, 0, 0] 0
[0, 0, 0] 0
Additional Information
- If you change the
const
tolet
the output is as expected.
$ nim -v
Nim Compiler Version 1.2.0 [Windows: amd64]
Compiled at 2020-04-03
Copyright (c) 2006-2020 by Andreas Rumpf
git hash: 7e83adff84be5d0c401a213eccb61e321a3fb1ff
active boot switches: -d:release
Metadata
Metadata
Assignees
Labels
No labels