mirror of
https://github.com/nim-lang/Nim.git
synced 2026-04-19 14:00:35 +00:00
enhance iterator test case, ensure consistency between inline and closure iterators regarding parameter passing semantics
This commit is contained in:
@@ -1,6 +1,14 @@
|
||||
discard """
|
||||
file: "titer3.nim"
|
||||
output: "1231"
|
||||
output: '''1231
|
||||
4
|
||||
6
|
||||
8
|
||||
--------
|
||||
4
|
||||
6
|
||||
8
|
||||
'''
|
||||
"""
|
||||
|
||||
iterator count1_3: int =
|
||||
@@ -17,6 +25,31 @@ iterator iter1(a: openArray[int]): int =
|
||||
|
||||
var x = [[1, 2, 3], [4, 5, 6]]
|
||||
for y in iter1(x[0]): write(stdout, $y)
|
||||
writeLine(stdout, "")
|
||||
|
||||
#OUT 1231
|
||||
# ensure closure and inline iterators have the same behaviour wrt
|
||||
# parameter passing
|
||||
|
||||
iterator clo(a: int): int {.closure.} =
|
||||
yield 0+a
|
||||
yield 1+a
|
||||
yield 2+a
|
||||
|
||||
iterator inl(a: int): int {.inline.} =
|
||||
yield 0+a
|
||||
yield 1+a
|
||||
yield 2+a
|
||||
|
||||
proc main =
|
||||
var y = 4
|
||||
for i in clo(y):
|
||||
echo i
|
||||
inc y
|
||||
|
||||
echo "--------"
|
||||
y = 4
|
||||
for i in inl(y):
|
||||
echo i
|
||||
inc y
|
||||
|
||||
main()
|
||||
|
||||
Reference in New Issue
Block a user