-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Cannot pass inline iterator to inline iterator #4516
Copy link
Copy link
Open
Labels
Description
This code works:
iterator test2(it: iterator(): int): int =
for i in it():
yield i*2
iterator test1(): int {.closure.} =
yield 10
yield 20
yield 30
for i in test2(test1()):
echo i
But this does not:
iterator test2(it: iterator(): int {.inline.}): int =
for i in it():
yield i*2
iterator test1(): int =
yield 10
yield 20
yield 30
for i in test2(test1()):
echo i
Error message:
test1.nim(2, 14) Error: type mismatch: got (int)
but expected one of:
iterator items[IX, T](a: array[IX, T]): T
iterator items[](E: typedesc[enum]): E:type
iterator items(a: string): char
iterator items[T](s: Slice[T]): T
iterator items[T](a: openArray[T]): T
iterator items[T](a: seq[T]): T
iterator items[T](a: set[T]): T
iterator items(a: cstring): char
The manual states that:
If the for loop expression e does not denote an iterator and the for loop has exactly 1 variable, the for loop expression is rewritten to items(e)
This seems to happen here although it is an iterator. The manual also states that
Inline iterators are second class citizens; They can be passed as parameters only to other inlining code facilities like templates, macros and other inline iterators.
So it should be possible to pass an inline iterator to another inline iterator. Therefore, I think this is a bug. This issue is originally a StackOverflow question.
Reactions are currently unavailable