diff --git a/src/basic.jl b/src/basic.jl index ccd9756..573e4e0 100644 --- a/src/basic.jl +++ b/src/basic.jl @@ -110,7 +110,14 @@ function Base.getindex(v::MemoryView, idx::AbstractUnitRange) isempty(idx) && return typeof(v)(unsafe, memoryref(v.ref.mem), 0) @boundscheck checkbounds(v, idx) newref = @inbounds memoryref(v.ref, Int(first(idx))::Int) - return typeof(v)(unsafe, newref, length(idx)) + return typeof(v)(unsafe, newref, Int(length(idx))::Int) +end + +function Base.getindex(v::MemoryView, idx::UnitRange{UInt}) + isempty(idx) && return typeof(v)(unsafe, memoryref(v.ref.mem), 0) + @boundscheck checkbounds(v, idx) + newref = @inbounds memoryref(v.ref, first(idx) % Int) + return typeof(v)(unsafe, newref, length(idx) % Int) end # Faster method, because we don't need to create a new memoryref, and also don't diff --git a/test/runtests.jl b/test/runtests.jl index e78980b..8d5cbbc 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -255,6 +255,13 @@ end @test_throws BoundsError mem[Base.OneTo(8)] @test_throws BoundsError mem[Base.OneTo(typemax(Int))] + + # UInt indexing + v = MemoryView([3, 4, 5, 6, 7]) + v2 = v[UInt(2):UInt(4)] + @test v2 == 4:6 + @test isempty(v2[UInt(2):UInt(1)]) + @test isempty(v2[UInt(6):UInt(5)]) end @testset "Views of memviews" begin