-
Notifications
You must be signed in to change notification settings - Fork 40
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
Generalize indexing AbstractUnitRanges with offset ranges #244
Conversation
Codecov Report
@@ Coverage Diff @@
## master #244 +/- ##
==========================================
+ Coverage 95.19% 95.26% +0.06%
==========================================
Files 5 5
Lines 416 422 +6
==========================================
+ Hits 396 402 +6
Misses 20 20
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The type piracy here is concerning; but seems no good way to appropriately avoid it.
Yes, I'll make a PR to move these methods to I'm also a bit concerned that this is quickly becoming a minefield of ambiguities. Not sure if there's an easy way around that either. |
Aqua only test if OffsetArrays introduces new ambiguity. We won't know if loading other packages introducing new Another possible downside of this piracy is that it would slow down the package loading via method invalidation. |
…tRange (#41224) Adding these methods lets `OffsetArrays` define `getindex(::AbstractUnitRange, ::IdentityUnitRange)` without ambiguities. This is in the domain of sanctioned type-piracy, as the result is an offset range in general and cannot be represented correctly using `Base` types. Re: JuliaArrays/OffsetArrays.jl#244 cc: @johnnychen94 Edit: this also fixes an indexing bug in `IdentityUntiRange`: master ```julia julia> r = Base.IdentityUnitRange(-3:3) Base.IdentityUnitRange(-3:3) julia> r[2] 2 julia> r[big(2)] -2 ``` Co-authored-by: jishnub <jishnub@users.noreply.github.com>
…tRange (JuliaLang#41224) Adding these methods lets `OffsetArrays` define `getindex(::AbstractUnitRange, ::IdentityUnitRange)` without ambiguities. This is in the domain of sanctioned type-piracy, as the result is an offset range in general and cannot be represented correctly using `Base` types. Re: JuliaArrays/OffsetArrays.jl#244 cc: @johnnychen94 Edit: this also fixes an indexing bug in `IdentityUntiRange`: master ```julia julia> r = Base.IdentityUnitRange(-3:3) Base.IdentityUnitRange(-3:3) julia> r[2] 2 julia> r[big(2)] -2 ``` Co-authored-by: jishnub <jishnub@users.noreply.github.com>
The main change is to define
getindex(::AbstractUnitRange, ::IdOffsetRange)
instead ofgetindex(::UnitRange, ::IdOffsetRange)
, and similarly forIdentityUnitRange
. This makes vector indexing preserve indices for custom unitrange types as well.on v1.6