Skip to content
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

Confusing error message when calling toSeq using a non-iterator #7182

Closed
dawkot opened this issue Feb 3, 2018 · 4 comments
Closed

Confusing error message when calling toSeq using a non-iterator #7182

dawkot opened this issue Feb 3, 2018 · 4 comments

Comments

@dawkot
Copy link

dawkot commented Feb 3, 2018

import sequtils

type A = object
iterator items(self: A): int = discard
discard toSeq(A())  #type mismatch: got (seq[A], int)

This works:

discard toSeq(A().items)

Normally "toSeq" calls the "items" iterator if it finds one on it's own.

toSeq(1..10)
@ghost
Copy link

ghost commented Feb 3, 2018

But should it?
1..10 is actually an iterator - https://github.com/nim-lang/Nim/blob/devel/lib/system.nim#L2036, and A() is not

@dawkot
Copy link
Author

dawkot commented Feb 3, 2018

My bad then.
Still, the error message is pretty confusing.

@dawkot dawkot changed the title "items" not called automatically by "toSeq" Confusing error message when calling toSeq using a non-iterator Feb 3, 2018
@ghost ghost added the Error Messages label Feb 3, 2018
@timotheecour
Copy link
Member

timotheecour commented Aug 25, 2018

/cc @Yardanico @daw

@narimiran
Copy link
Member

#8711 actually makes your test case work

That is now merged and this indeed works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants