Skip to content
This repository has been archived by the owner on Sep 1, 2020. It is now read-only.

nth does not correctly check the length of infinite iterators #100

Closed
phipsgabler opened this issue Apr 4, 2017 · 0 comments
Closed

nth does not correctly check the length of infinite iterators #100

phipsgabler opened this issue Apr 4, 2017 · 0 comments

Comments

@phipsgabler
Copy link

phipsgabler commented Apr 4, 2017

I run into the following problem in 0.5.1:

julia> nth(drop(repeatedly(() -> 1), 1), 1)
ERROR: MethodError: no method matching length(::Iterators.RepeatCallForever)
Closest candidates are:
  length(!Matched::SimpleVector) at essentials.jl:168
  length(!Matched::Base.MethodList) at reflection.jl:256
  length(!Matched::MethodTable) at reflection.jl:322
  ...
 in nth(::Base.Drop{Iterators.RepeatCallForever}, ::Int64) at /home/philipp/.julia/v0.5/Iterators/src/Iterators.jl:497

Since this seems to be due to this line: I can replicate it with

julia> applicable(length, drop(repeatedly(() -> 1), 1))
true

julia> length(drop(repeatedly(() -> 1), 1))
ERROR: MethodError: no method matching length(::Iterators.RepeatCallForever)
Closest candidates are:
  length(!Matched::SimpleVector) at essentials.jl:168
  length(!Matched::Base.MethodList) at reflection.jl:256
  length(!Matched::MethodTable) at reflection.jl:322
  ...
 in length(::Base.Drop{Iterators.RepeatCallForever}) at ./iterator.jl:371

julia> Base.iteratorsize(drop(repeatedly(() -> 1), 1))
Base.IsInfinite()

and I think that checking for IsInfinite somehow should prevent this.

iamed2 added a commit that referenced this issue Apr 5, 2017
@iamed2 iamed2 closed this as completed in 1864ed0 Apr 7, 2017
iamed2 added a commit that referenced this issue Apr 7, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant