From e71c8247edcc43539ef202c38ba95db5131429a4 Mon Sep 17 00:00:00 2001 From: Tim Holy Date: Sat, 1 Sep 2018 05:59:41 -0500 Subject: [PATCH] Fix ambiguities and test for them --- src/closed.jl | 8 ++++++++ test/runtests.jl | 2 ++ 2 files changed, 10 insertions(+) diff --git a/src/closed.jl b/src/closed.jl index 831be7c..c537cf7 100644 --- a/src/closed.jl +++ b/src/closed.jl @@ -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 diff --git a/test/runtests.jl b/test/runtests.jl index a958264..fc33380 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -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)