Skip to content

Commit 3128af5

Browse files
authored
Merge pull request #37 from JuliaMath/teh/fix_ambig
Fix ambiguities and test for them
2 parents 77a5e3b + e71c824 commit 3128af5

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

src/closed.jl

+8
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,14 @@ function convert(::Type{R}, i::ClosedInterval{I}) where {R<:AbstractUnitRange,I<
100100
R(minimum(i), maximum(i))
101101
end
102102

103+
# The third is the one we want, but the first two are needed to resolve ambiguities
104+
Base.Slice{T}(i::ClosedInterval{I}) where {T<:AbstractUnitRange,I<:Integer} =
105+
Base.Slice{T}(minimum(i):maximum(i))
106+
function Base.OneTo{T}(i::ClosedInterval{I}) where {T<:Integer,I<:Integer}
107+
@noinline throwstart(i) = throw(ArgumentError("smallest element must be 1, got $(minimum(i))"))
108+
minimum(i) == 1 || throwstart(i)
109+
Base.OneTo{T}(maximum(i))
110+
end
103111
function (::Type{R})(i::ClosedInterval{I}) where {R<:AbstractUnitRange,I<:Integer}
104112
R(minimum(i), maximum(i))
105113
end

test/runtests.jl

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ using Compat
33
using Compat.Test
44
using Compat.Dates
55

6+
@test isempty(detect_ambiguities(IntervalSets, Base, Core))
7+
68
@testset "IntervalSets" begin
79
@test ordered(2, 1) == (1, 2)
810
@test ordered(1, 2) == (1, 2)

0 commit comments

Comments
 (0)