diff --git a/base/range.jl b/base/range.jl index af28228cd74ac9..517d0456db5e8e 100644 --- a/base/range.jl +++ b/base/range.jl @@ -608,8 +608,8 @@ function getindex(v::AbstractRange{T}, i::Integer) where T @_inline_meta ret = convert(T, first(v) + (i - 1)*step_hp(v)) ok = ifelse(step(v) > zero(step(v)), - (ret <= v.stop) & (ret >= v.start), - (ret <= v.start) & (ret >= v.stop)) + (ret <= last(v)) & (ret >= first(v)), + (ret <= first(v)) & (ret >= last(v))) @boundscheck ((i > 0) & ok) || throw_boundserror(v, i) ret end diff --git a/stdlib/SparseArrays/test/sparse.jl b/stdlib/SparseArrays/test/sparse.jl index 79290cfc6433c9..76dd90bc74c480 100644 --- a/stdlib/SparseArrays/test/sparse.jl +++ b/stdlib/SparseArrays/test/sparse.jl @@ -92,6 +92,10 @@ do33 = fill(1.,3) end end +@testset "Issue #30006" begin + SparseMatrixCSC{Float64,Int32}(spzeros(3,3))[:, 1] == [1, 2, 3] +end + @testset "concatenation tests" begin sp33 = sparse(1.0I, 3, 3) diff --git a/test/ranges.jl b/test/ranges.jl index cfb41a477ebef6..dba2e8b24983cc 100644 --- a/test/ranges.jl +++ b/test/ranges.jl @@ -1406,6 +1406,13 @@ end @test @inferred(z4 .+ z4) === z4 end +@testset "Issue #30006" begin + @test Base.Slice(Base.OneTo(5))[Int32(1)] == Int32(1) + @test Base.Slice(Base.OneTo(3))[Int8(2)] == Int8(2) + @test Base.Slice(1:10)[Int32(2)] == Int32(2) + @test Base.Slice(1:10)[Int8(2)] == Int8(2) +end + @testset "allocation of TwicePrecision call" begin 0:286.493442:360 0:286:360