-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Iterators in combination with closures misbehave #3837
Comments
proc toIter*[T](i: iterator: T): iterator: T =
## Nop
i This is not a nop. No idea if that's the problem though. |
I think this might be a minimal example of this problem: iterator t1(): int {.closure.} =
yield 1
iterator t2(): int {.closure.} =
for i in t1():
yield i
for i in t2():
echo $i This fails with
However, if we take out the first |
@shaunc The minimal example now works correctly. Not so for the original one, though |
I think I've a shorter example: proc iter1(): (iterator: int) =
let coll = [0,1,2]
result = iterator: int {.closure.} =
for i in coll:
yield i
proc iter2(it: (iterator: int)): (iterator: int) =
result = iterator: int {.closure.} =
echo finished(it)
for i in it():
yield i
echo "start"
let myiter1 = iter1()
let myiter2 = iter2(myiter1)
for i in myiter2():
echo i
echo "end"
# start
# false
# end But it works when changing the proc iter2(it: (iterator: int)): (iterator: int) =
result = iterator: int {.closure.} =
while true:
let i = it()
if finished(it): break
yield i Doing this instead of |
This is extracted from https://github.com/def-/nim-iterutils . Since it compiles for the first time since Nimrod 0.9.4, I'm not sure what exactly broke it. I believe this to be related to the closure changes and tried the suggested changes, but couldn't fix it:
The text was updated successfully, but these errors were encountered: