You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The following code compiles with compiler versions before commit 34b4e9f, and fails with later versions:
import macros
templateforStatic(index: expr, slice: Slice[int], predicate: stmt):
stmt {.immediate.} =const a = slice.a
const b = slice.b
when a <= b:
templateiteration(i: int) =block:
const index = i
predicate
templateiterateStartingFrom(i: int): stmt =when i <= b:
iteration i
iterateStartingFrom i +1iterateStartingFrom a
procconcreteProc(x: int) =forStatic i, 0..3:
echo i
procgenericProc(x: any) =forStatic i, 0..3:
echo i
concreteProc(7) # This worksgenericProc(7) # This doesn't compile
The error message:
test.nim(28, 11) Info: template/generic instantiation from here
test.nim(17, 4) Info: template/generic instantiation from here
test.nim(15, 8) Info: template/generic instantiation from here
test.nim(11, 22) Error: cannot evaluate at compile time: x
However, variations on this code can cause
Symbols that are not integers being converted to type int.
Internal errors in genRecordField.
Use-case/significance: All of my current projects use some version of the forStatic snippet for compile-time iteration. It's the most straightforward approach to manipulating elements of generic arrays/tuples without actually generating loops (which may be too expensive in some situations, e.g. transforming tensor indices).
The text was updated successfully, but these errors were encountered:
The following code compiles with compiler versions before commit 34b4e9f, and fails with later versions:
The error message:
However, variations on this code can cause
int
.genRecordField
.Use-case/significance: All of my current projects use some version of the
forStatic
snippet for compile-time iteration. It's the most straightforward approach to manipulating elements of generic arrays/tuples without actually generating loops (which may be too expensive in some situations, e.g. transforming tensor indices).The text was updated successfully, but these errors were encountered: