From 1fda0199c3cbd242757d902b1e4b272a5faf5055 Mon Sep 17 00:00:00 2001 From: raghav9-97 Date: Sun, 16 Dec 2018 16:36:31 +0530 Subject: [PATCH 1/2] Modified getindex(::AbstractRange) --- base/range.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/base/range.jl b/base/range.jl index 785ade602f6bf..edf616d4d171f 100644 --- a/base/range.jl +++ b/base/range.jl @@ -627,8 +627,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 From e5129f2bf8d93bcc3ce414e4688973b127828240 Mon Sep 17 00:00:00 2001 From: raghav9-97 Date: Mon, 17 Dec 2018 12:51:00 +0530 Subject: [PATCH 2/2] Added tests Issue#30006 --- stdlib/SparseArrays/test/sparse.jl | 4 ++++ test/ranges.jl | 7 +++++++ 2 files changed, 11 insertions(+) diff --git a/stdlib/SparseArrays/test/sparse.jl b/stdlib/SparseArrays/test/sparse.jl index b53a281c71b26..8dfa692967aef 100644 --- a/stdlib/SparseArrays/test/sparse.jl +++ b/stdlib/SparseArrays/test/sparse.jl @@ -93,6 +93,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 f699eca7a1d98..55ef8dded94e5 100644 --- a/test/ranges.jl +++ b/test/ranges.jl @@ -1412,6 +1412,13 @@ end @test getindex((typemax(UInt64)//one(UInt64):typemax(UInt64)//one(UInt64)), 1) == typemax(UInt64)//one(UInt64) 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