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

Wrapping a closure iterator leads to execution of an external program failed #2532

Closed
bluenote10 opened this issue Apr 12, 2015 · 3 comments
Closed

Comments

@bluenote10
Copy link
Contributor

The following code fails to compile. It was a bit difficult to isolate the problem: Strangely, the problem disappears by removing either the when condition or one of the loops:

when true: # removing 'when' indentation => compiles

  iterator iter(): int {.closure.} =
    yield 0
    yield 1

  iterator wrappedIterator(it: iterator (): int): int {.closure.} =
    for x in it():
      yield x

  # Removing this loop => compiles, but
  # the behavior of the second loop is strange:
  # It is an infinite loop, always returning zero
  for x in iter():
    echo x

  # Removing this loop => compiles, and above
  # loop works fine.
  for x in iter.wrappedIterator:
    echo x

The compilation error is:

/home/fabian/github/NimExperiments/nimcache/repeatedIteratorUse.c: In function ‘repeatedIteratorUseInit’:
/home/fabian/github/NimExperiments/nimcache/repeatedIteratorUse.c:267:42: error: ‘HEX3Aenv_90222’ undeclared (first use in this function)
    LOC8.ClPrc = iter_90003; LOC8.ClEnv = HEX3Aenv_90222;
                                      ^
/home/fabian/github/NimExperiments/nimcache/repeatedIteratorUse.c:267:42: note: each undeclared identifier is reported only once for each function it appears in

I also do not understand why iter.wrappedIterator causes an infinite loop in the first place. Is this behavior expected? From my newbie point of view, I was expecting just to get the exact same iteration as in the first loop.

(Nim 0.10.3 -- using 28ecf72)

@bluenote10
Copy link
Contributor Author

For sake of completeness: There is now a separate issue #2563 addressing the cause of the infinite loop I observed. Thus, this issue is only about the compilation error.

@dom96
Copy link
Contributor

dom96 commented Jan 16, 2016

Compiles as of devel.

@dom96 dom96 closed this as completed Jan 16, 2016
@dom96
Copy link
Contributor

dom96 commented Jan 16, 2016

The behaviour of the compiled program is still an infinite loop. I assume #2563 talks about that issue though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants