Skip to content

Commit

Permalink
Merge pull request #12291 from JuliaLang/jcb/12278
Browse files Browse the repository at this point in the history
Add explicit partial empty range check for UInt UnitRange's
  • Loading branch information
jakebolewski committed Jul 24, 2015
2 parents 4c7a9d0 + d2d2e43 commit 19b64d2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
5 changes: 4 additions & 1 deletion base/range.jl
Original file line number Diff line number Diff line change
Expand Up @@ -283,9 +283,12 @@ function length{T<:Union{Int,UInt,Int64,UInt64}}(r::StepRange{T})
end
end

length{T<:Union{Int,UInt,Int64,UInt64}}(r::UnitRange{T}) =
length{T<:Union{Int,Int64}}(r::UnitRange{T}) =
checked_add(checked_sub(r.stop, r.start), one(T))

length{T<:Union{UInt,UInt64}}(r::UnitRange{T}) =
r.stop < r.start ? zero(T) : checked_add(r.stop - r.start, one(T))

# some special cases to favor default Int type
let smallint = (Int === Int64 ?
Union{Int8,UInt8,Int16,UInt16,Int32,UInt32} :
Expand Down
3 changes: 3 additions & 0 deletions test/ranges.jl
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,9 @@ end
# issue #8584
@test (0:1//2:2)[1:2:3] == 0:1//1:1

# issue #12278
@test length(1:UInt(0)) == 0

# zip
let i = 0
x = 1:2:8
Expand Down

0 comments on commit 19b64d2

Please sign in to comment.