-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Internal error with auto return in closure iterator #5859
Labels
Comments
Another error with genTypeInfo, if it's not related I will open another case: proc flatIterator[N,T](s: array[N, T], U: typedesc): iterator(): U {.noSideEffect.}=
result = iterator(): U =
when T is array:
let it = flatIterator(s, U)
for item in it():
yield item
else:
for item in s:
yield item
let it = flatIterator([[1,2],[3,4]], int) Error:
|
For reference this is the working code I use that avoids all those issues iterator flatIter[T](s: openarray[T]): auto {.noSideEffect.}=
## Inline iterator on any-depth seq or array
## Returns values in order
for item in s:
when item is array|seq:
for subitem in flatIter(item):
yield subitem
else:
yield item |
@mratsim for info - this compiles with devel: proc flatIterator[N,T](s: array[N, T], U: typedesc): iterator(): U {.noSideEffect.}=
result = iterator(): U =
when T is array:
let it = flatIterator(s, U)
for item in it():
yield item
else:
for item in s:
yield item
let it = flatIterator([[1,2],[3,4]], int) |
All examples here compile (except for the one that was said to work :-). The infinite recursion blows the stack though, but if modified works fine. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I stumbled upon the following internal error with the following code:
Error
Changing the signature to int works
Context:
Following @zah suggestion in #5708. I'm trying to create a flat iterator that iterates on arbitrary nested openarrays. Inline iterators cannot be recursive (#555) so I'm trying through a closure iterator.
The text was updated successfully, but these errors were encountered: