Skip to content

Commit

Permalink
Merge pull request #37 from JuliaMath/teh/fix_ambig
Browse files Browse the repository at this point in the history
Fix ambiguities and test for them
  • Loading branch information
timholy authored Sep 1, 2018
2 parents 77a5e3b + e71c824 commit 3128af5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/closed.jl
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,14 @@ function convert(::Type{R}, i::ClosedInterval{I}) where {R<:AbstractUnitRange,I<
R(minimum(i), maximum(i))
end

# The third is the one we want, but the first two are needed to resolve ambiguities
Base.Slice{T}(i::ClosedInterval{I}) where {T<:AbstractUnitRange,I<:Integer} =
Base.Slice{T}(minimum(i):maximum(i))
function Base.OneTo{T}(i::ClosedInterval{I}) where {T<:Integer,I<:Integer}
@noinline throwstart(i) = throw(ArgumentError("smallest element must be 1, got $(minimum(i))"))
minimum(i) == 1 || throwstart(i)
Base.OneTo{T}(maximum(i))
end
function (::Type{R})(i::ClosedInterval{I}) where {R<:AbstractUnitRange,I<:Integer}
R(minimum(i), maximum(i))
end
Expand Down
2 changes: 2 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ using Compat
using Compat.Test
using Compat.Dates

@test isempty(detect_ambiguities(IntervalSets, Base, Core))

@testset "IntervalSets" begin
@test ordered(2, 1) == (1, 2)
@test ordered(1, 2) == (1, 2)
Expand Down

0 comments on commit 3128af5

Please sign in to comment.