<commit_before>discard """
  output: '''b yields
c yields
a returns
b yields
b returns
c yields


1
2
3
4
'''
"""

block:
  template tloop(iter: untyped) =
    for i in iter():
      echo i

  template twhile(iter: untyped) =
    let it = iter
    while not finished(it):
      echo it()

  iterator a(): auto {.closure.} =
    if true: return "a returns"
    yield "a yields"

  iterator b(): auto {.closure.} =
    yield "b yields"
    if true: return "b returns"

  iterator c(): auto {.closure.} =
    yield "c yields"
    if true: return

  iterator d(): auto {.closure.} =
    if true: return
    yield "d yields"

  tloop(a)
  tloop(b)
  tloop(c)
  tloop(d)
  twhile(a)
  twhile(b)
  twhile(c)
  twhile(d)

block:
  iterator a: auto =
    yield 1
  for x in a():
    echo x

  let b = iterator: int =
    yield 2
  for x in b():
    echo x

  let c = iterator: auto =
    yield 3
  for x in c():
    echo x

block:
  iterator myIter2(): auto {.closure.} =
    yield 4
  for a in myIter2():
    echo a<commit_msg>close #5859 by adding a test<commit_after>discard """
  output: '''b yields
c yields
a returns
b yields
b returns
c yields


1
2
3
4
'''
"""

block:
  template tloop(iter: untyped) =
    for i in iter():
      echo i

  template twhile(iter: untyped) =
    let it = iter
    while not finished(it):
      echo it()

  iterator a(): auto {.closure.} =
    if true: return "a returns"
    yield "a yields"

  iterator b(): auto {.closure.} =
    yield "b yields"
    if true: return "b returns"

  iterator c(): auto {.closure.} =
    yield "c yields"
    if true: return

  iterator d(): auto {.closure.} =
    if true: return
    yield "d yields"

  tloop(a)
  tloop(b)
  tloop(c)
  tloop(d)
  twhile(a)
  twhile(b)
  twhile(c)
  twhile(d)

block:
  iterator a: auto =
    yield 1
  for x in a():
    echo x

  let b = iterator: int =
    yield 2
  for x in b():
    echo x

  let c = iterator: auto =
    yield 3
  for x in c():
    echo x

block:
  iterator myIter2(): auto {.closure.} =
    yield 4
  for a in myIter2():
    echo a

block t5859:
  proc flatIterator[T](s: openarray[T]): auto {.noSideEffect.}=
    result = iterator(): auto =
      when (T is not seq|array):
        for item in s:
          yield item
      else:
        yield 123456
  # issue #5859
  let it = flatIterator(@[@[1,2], @[3,4]])
{'fraction_non_alphanumeric': 0.12821612349914235, 'fraction_numerical': 0.018010291595197257, 'mean_word_length': 2.262937062937063, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3791290', 'n_tokens_mistral': 890, 'n_tokens_neox': 853, 'n_words': 314}