JuliaLang / julia

The Julia Programming Language
https://julialang.org/
MIT License
45k stars 5.42k forks source link

bugs involving `IdentityUnitRange` #54783

Open matthias314 opened 3 weeks ago

matthias314 commented 3 weeks ago

The code in range.jl was presumably written under the assumption that all ranges (or all arrays) are 1-based. With IdentityUnitRange, this is not true anymore, and this leads to problems. I have found the following issues: For

u = 2:4
v = Base.IdentityUnitRange(2:4)
w = 1:9

one gets:

julia> axes(u) == axes(v), u == v     # equal arrays must have equal axes
(false, true)

julia> w[v][2], w[v[2]]     # the documentation defines w[v][i] to be w[v[i]]
(3, 2)

This happens with Julia 1.10.4, 1.11.0-beta2 and master.

EDIT: I've just noticed that while IdentityUnitRange has a docstring, it is not mentioned in the documentation. Maybe it is considered internal.

jishnub commented 3 weeks ago

I don't think this is fixable without being somewhat breaking, see https://github.com/JuliaLang/julia/pull/30950

matthias314 commented 3 weeks ago

I'm not so sure. My understanding is that #30950 is about some weird results when broadcasting over 1-element arrays. For the moment I've looked more closely at comparisons of ranges. I don't see why this couldn't be changed, but of course I might miss something. To get a better idea, I've created the PR #54825. Maybe this way one can see better what would happen with such a change.