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
When defining an iterator variable, the program compiles successfully if the variable is global but causes an internal compiler error if it is local.
Example
The following program compiles and execute without any problem:
iteratoriter(n: int): int {.closure.} =for i in1..n:
yield i
var it =iterator: int= (for i initer(5): yield i)
echoit()
echoit()
But moving the definition of "it" in a procedure makes the compiler encounter an internal error: internal error: expr: var not init iter_4607114
iteratoriter(n: int): int {.closure.} =for i in1..n:
yield i
procp() =var it =iterator: int= (for i initer(5): yield i)
echoit()
echoit()
p()
Current Output
internal error: expr: var not init iter_4607114
The error exists with devel compiler too.
Expected Output
No internal error, of course.
Possible Solution
Adding {.closure.} to the iterator defining the variable doesn’t solve the issue.
But changing the closure iterator to an inline iterator solves it.
Additional Information
There are previous issues related to iterator variable but as far as I know they are considered as closed.
$ nim -v
Nim Compiler Version 1.4.4 [Linux: amd64]
The text was updated successfully, but these errors were encountered:
lscrd
changed the title
Compiler internal error when defining local variable iterator.
Compiler internal error when defining local iterator variable.
Apr 3, 2021
When defining an iterator variable, the program compiles successfully if the variable is global but causes an internal compiler error if it is local.
Example
The following program compiles and execute without any problem:
But moving the definition of "it" in a procedure makes the compiler encounter an internal error:
internal error: expr: var not init iter_4607114
Current Output
internal error: expr: var not init iter_4607114
The error exists with devel compiler too.
Expected Output
No internal error, of course.
Possible Solution
Adding {.closure.} to the iterator defining the variable doesn’t solve the issue.
But changing the closure iterator to an inline iterator solves it.
Additional Information
There are previous issues related to iterator variable but as far as I know they are considered as closed.
The text was updated successfully, but these errors were encountered: