Skip to content

Commit

Permalink
remove tuple indexing by non-integer (#43760)
Browse files Browse the repository at this point in the history
Co-authored-by: Fredrik Ekre <ekrefredrik@gmail.com>
Co-authored-by: Simeon Schaub <schaub@mit.edu>
  • Loading branch information
3 people authored Feb 11, 2022
1 parent a557536 commit 4409a1b
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 7 deletions.
1 change: 1 addition & 0 deletions base/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -268,5 +268,6 @@ end

@deprecate var"@_inline_meta" var"@inline" false
@deprecate var"@_noinline_meta" var"@noinline" false
@deprecate getindex(t::Tuple, i::Real) t[convert(Int, i)]

# END 1.8 deprecations
2 changes: 1 addition & 1 deletion base/tuple.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ lastindex(@nospecialize t::Tuple) = length(t)
size(@nospecialize(t::Tuple), d::Integer) = (d == 1) ? length(t) : throw(ArgumentError("invalid tuple dimension $d"))
axes(@nospecialize t::Tuple) = (OneTo(length(t)),)
@eval getindex(@nospecialize(t::Tuple), i::Int) = getfield(t, i, $(Expr(:boundscheck)))
@eval getindex(@nospecialize(t::Tuple), i::Real) = getfield(t, convert(Int, i), $(Expr(:boundscheck)))
@eval getindex(@nospecialize(t::Tuple), i::Integer) = getfield(t, convert(Int, i), $(Expr(:boundscheck)))
getindex(t::Tuple, r::AbstractArray{<:Any,1}) = (eltype(t)[t[ri] for ri in r]...,)
getindex(t::Tuple, b::AbstractArray{Bool,1}) = length(b) == length(t) ? getindex(t, findall(b)) : throw(BoundsError(t, b))
getindex(t::Tuple, c::Colon) = t
Expand Down
8 changes: 8 additions & 0 deletions test/deprecation_exec.jl
Original file line number Diff line number Diff line change
Expand Up @@ -120,3 +120,11 @@ global_logger(prev_logger)
end

# END 0.7 deprecations

@testset "tuple indexed by float deprecation" begin
@test_deprecated getindex((1,), 1.0) === 1
@test_deprecated getindex((1,2), 2.0) === 2
@test_throws Exception getindex((), 1.0)
@test_throws Exception getindex((1,2), 0.0)
@test_throws Exception getindex((1,2), -1.0)
end
6 changes: 0 additions & 6 deletions test/tuple.jl
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,6 @@ end
@test_throws BoundsError getindex((1,2), 0)
@test_throws BoundsError getindex((1,2), -1)

@test getindex((1,), 1.0) === 1
@test getindex((1,2), 2.0) === 2
@test_throws BoundsError getindex((), 1.0)
@test_throws BoundsError getindex((1,2), 0.0)
@test_throws BoundsError getindex((1,2), -1.0)

@test getindex((5,6,7,8), [1,2,3]) === (5,6,7)
@test_throws BoundsError getindex((1,2), [3,4])

Expand Down

0 comments on commit 4409a1b

Please sign in to comment.