Skip to content

Commit 4409a1b

Browse files
oscardssmithfredrikekresimeonschaub
authored
remove tuple indexing by non-integer (#43760)
Co-authored-by: Fredrik Ekre <ekrefredrik@gmail.com> Co-authored-by: Simeon Schaub <schaub@mit.edu>
1 parent a557536 commit 4409a1b

File tree

4 files changed

+10
-7
lines changed

4 files changed

+10
-7
lines changed

base/deprecated.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,5 +268,6 @@ end
268268

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

272273
# END 1.8 deprecations

base/tuple.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ lastindex(@nospecialize t::Tuple) = length(t)
2727
size(@nospecialize(t::Tuple), d::Integer) = (d == 1) ? length(t) : throw(ArgumentError("invalid tuple dimension $d"))
2828
axes(@nospecialize t::Tuple) = (OneTo(length(t)),)
2929
@eval getindex(@nospecialize(t::Tuple), i::Int) = getfield(t, i, $(Expr(:boundscheck)))
30-
@eval getindex(@nospecialize(t::Tuple), i::Real) = getfield(t, convert(Int, i), $(Expr(:boundscheck)))
30+
@eval getindex(@nospecialize(t::Tuple), i::Integer) = getfield(t, convert(Int, i), $(Expr(:boundscheck)))
3131
getindex(t::Tuple, r::AbstractArray{<:Any,1}) = (eltype(t)[t[ri] for ri in r]...,)
3232
getindex(t::Tuple, b::AbstractArray{Bool,1}) = length(b) == length(t) ? getindex(t, findall(b)) : throw(BoundsError(t, b))
3333
getindex(t::Tuple, c::Colon) = t

test/deprecation_exec.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,3 +120,11 @@ global_logger(prev_logger)
120120
end
121121

122122
# END 0.7 deprecations
123+
124+
@testset "tuple indexed by float deprecation" begin
125+
@test_deprecated getindex((1,), 1.0) === 1
126+
@test_deprecated getindex((1,2), 2.0) === 2
127+
@test_throws Exception getindex((), 1.0)
128+
@test_throws Exception getindex((1,2), 0.0)
129+
@test_throws Exception getindex((1,2), -1.0)
130+
end

test/tuple.jl

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -150,12 +150,6 @@ end
150150
@test_throws BoundsError getindex((1,2), 0)
151151
@test_throws BoundsError getindex((1,2), -1)
152152

153-
@test getindex((1,), 1.0) === 1
154-
@test getindex((1,2), 2.0) === 2
155-
@test_throws BoundsError getindex((), 1.0)
156-
@test_throws BoundsError getindex((1,2), 0.0)
157-
@test_throws BoundsError getindex((1,2), -1.0)
158-
159153
@test getindex((5,6,7,8), [1,2,3]) === (5,6,7)
160154
@test_throws BoundsError getindex((1,2), [3,4])
161155

0 commit comments

Comments
 (0)