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

iterator in anonymous proc yields empty result #7787

Open
michael72 opened this issue May 6, 2018 · 0 comments
Open

iterator in anonymous proc yields empty result #7787

michael72 opened this issue May 6, 2018 · 0 comments

Comments

@michael72
Copy link

michael72 commented May 6, 2018

I found a strange bug/behavior when working with an anoymous proc that contains an iterator (the proc was generated by macros).
The iterator does not yield a result.

Example code:

proc chkConversion(x: seq[int]): seq[string] =
  result = (proc (): seq[string] =
    iterator autoIter(): auto =
      for it0 in x:
        let it1 = $it0
        yield it1

    result = @[]
    for it in autoIter():
      result.add(it))()

proc chkConversion2(x: seq[int]): seq[string] =
  result = @[]
  iterator autoIter(): auto =
    for it0 in x:
      let it1 = $it0
      yield it1
  
  for it in autoIter():
    result.add(it)

when isMainModule:
  echo("calling not working iterator:")
  echo(chkConversion(@[1,2,3,4,5]))
  echo("calling working iterator:")
  echo(chkConversion2(@[1,2,3,4,5]))

The resulting output is

calling not working iterator:
@[]
calling working iterator:
@["1", "2", "3", "4", "5"]
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

2 participants