It seems inconsistent that collect(zip(1:3, 1:10)) throws a DimensionMismatch error:
julia> collect(zip(1:3, 1:10))
ERROR: DimensionMismatch("dimensions must match: a has dims (Base.OneTo(3),), b has dims (Base.OneTo(10),), mismatch at 1")
Stacktrace:
[1] promote_shape at ./indices.jl:178 [inlined]
[2] _promote_shape at ./iterators.jl:318 [inlined]
[3] axes at ./iterators.jl:317 [inlined]
[4] _similar_for at ./array.jl:578 [inlined]
[5] _collect(::UnitRange{Int64}, ::Base.Iterators.Zip{Tuple{UnitRange{Int64},UnitRange{Int64}}}, ::Base.HasEltype, ::Base.HasShape{1}) at ./array.jl:609
[6] collect(::Base.Iterators.Zip{Tuple{UnitRange{Int64},UnitRange{Int64}}}) at ./array.jl:603
[7] top-level scope at REPL[2]:1
but
for (i,j) in zip(1:3, 1:10)
...
end
runs fine. Also the docs for zip say that it will just stop when the first iterator runs out, not that it will error if the iterators have different lengths.
In general I think we should allow zip to accept iterators of different length and be consistent with this.
Another weird example:
g = (i for i = 1:10^6 if iseven(i))
zip(1:10, 1:3, g) |> collect # works without error
zip(1:10, 1:3) |> collect # DimensionMismatch error
This is indeed a bug. It looks like axes is wrongly implemented for zip.
IteratorSize returns HasShape{1}(), but the documentation for IteratorSize states that anything has returns a HasShape should have axes defined for it. axes(::Zip) uses promote_shape, which does not reflect the actual size of a zip object.
This was likely fixed by #29927 (I can't reproduce the reported errors on Julia 1.5).
Most helpful comment
This was likely fixed by #29927 (I can't reproduce the reported errors on Julia 1.5).