-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Open
Labels
const`const x=expr` or `static: stmt``const x=expr` or `static: stmt`
Description
Code
type ProcType = proc()
const a: ProcType = proc() = discard
const arr: array[8, ProcType] = [a, a, a, a, a, a, a, a]
for i in 0..<arr.len:
echo "[", i, "]: ", arr[i].isNil
echo "\nwith constant index:\n[7]: ", arr[7].isNilCurrent Output
[0]: false
[1]: false
[2]: false
[3]: false
[4]: true
[5]: true
[6]: true
[7]: true
with constant index:
[7]: false
Expected Output
[0]: false
[1]: false
[2]: false
[3]: false
[4]: false
[5]: false
[6]: false
[7]: false
with constant index:
[7]: false
Workarounds
- Declaring both the proc and the array as
varfixes the problem in this test case. In my codebase, it leads to invalid codegen that I have been unable to isolate.
Additional Information
- Occurs in 1.4.2 as well as latest HEAD
- Occurs with and without
--gc:arc - Likely related to
constproc inletarray causes invalid codegen #16736
$ nim -v
Nim Compiler Version 1.5.1 [Linux: amd64]
Compiled at 2021-01-16
Copyright (c) 2006-2021 by Andreas Rumpf
44ceefa9fefca58ba32e9638f754d7f4ca8a2b82 (current git head)
Metadata
Metadata
Assignees
Labels
const`const x=expr` or `static: stmt``const x=expr` or `static: stmt`