Iterator fixes (#11234)

This commit is contained in:
Jasper Jenkins 2019-05-13 11:50:21 -07:00 • committed by Andreas Rumpf
commit 6fc74cec55
8 changed files with 142 additions and 17 deletions

72
tests/iter/titer13.nim Normal file
View file

@ -0,0 +1,72 @@
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