Skip to content
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

closure iterator assertionError on nested for loop #6739

Closed
nitely opened this issue Nov 13, 2017 · 1 comment
Closed

closure iterator assertionError on nested for loop #6739

nitely opened this issue Nov 13, 2017 · 1 comment

Comments

@nitely
Copy link
Contributor

nitely commented Nov 13, 2017

The following code throws an assertion error:

iterator myiterclosure(cps: seq[int]): int {.closure.} =
  echo cps
  for cp in cps:
    echo "loop"
    var dcps: seq[int] = @[1,2]
    for dcp in dcps:
      yield dcp
    echo cps
  echo "end"

var myseqnum = @[1,2,3,4,5]
for myI in myiterclosure(myseqnum):
  echo myI
$ nim --run c some
@[1, 2, 3, 4, 5]
loop
1
2
@[1, 2, 3, 4, 5]
Traceback (most recent call last)
mybuggyiterator.nim(13)  mybuggyiterator
system.nim(3772)         myiterclosure
system.nim(3741)         failedAssertImpl
system.nim(3733)         raiseAssert
system.nim(2799)         sysFatal
Error: unhandled exception: len(a) == L seq modified while iterating over it [AssertionError]

Tried on devel

Edit: works if I remove the inner loop.

@nitely
Copy link
Contributor Author

nitely commented Nov 14, 2017

Nevermind, I've been bitten by #2563 . The behaviour is well explained in the manual

@nitely nitely closed this as completed Nov 14, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant