`nth` does not correctly check the length of infinite iterators
Closed this issue · 0 comments
phipsgabler commented
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.