From 6bc3738a9d8e4680f77693bdef02b3434ddea3da Mon Sep 17 00:00:00 2001 From: Tim Holy Date: Fri, 17 Feb 2017 08:20:29 -0600 Subject: [PATCH] Fix typealias and inner constructor depwarns on 0.6 --- REQUIRE | 3 ++- src/IntervalSets.jl | 5 ++++- src/closed.jl | 2 +- test/runtests.jl | 7 ++----- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/REQUIRE b/REQUIRE index 70e314a..23848d5 100644 --- a/REQUIRE +++ b/REQUIRE @@ -1 +1,2 @@ -julia 0.5- +julia 0.5 +Compat 0.18 diff --git a/src/IntervalSets.jl b/src/IntervalSets.jl index 50d3c21..0507f86 100644 --- a/src/IntervalSets.jl +++ b/src/IntervalSets.jl @@ -7,9 +7,11 @@ module IntervalSets using Base: @pure import Base: eltype, convert, show, in, length, isempty, isequal, issubset, ==, hash, union, intersect, minimum, maximum +using Compat + export AbstractInterval, ClosedInterval, ⊇, .., ±, ordered, width -abstract AbstractInterval{T} +@compat abstract type AbstractInterval{T} end include("closed.jl") @@ -27,6 +29,7 @@ ordered(a, b) = ordered(promote(a, b)...) checked_conversion{T}(::Type{T}, a, b) = _checked_conversion(T, convert(T, a), convert(T, b)) _checked_conversion{T}(::Type{T}, a::T, b::T) = a, b +_checked_conversion(::Type{Any}, a, b) = throw(ArgumentError("$a and $b promoted to type Any")) _checked_conversion{T}(::Type{T}, a, b) = throw(ArgumentError("$a and $b are not both of type $T")) end # module diff --git a/src/closed.jl b/src/closed.jl index e86576f..5d1cb13 100644 --- a/src/closed.jl +++ b/src/closed.jl @@ -6,7 +6,7 @@ immutable ClosedInterval{T} <: AbstractInterval{T} left::T right::T - ClosedInterval(l::T, r::T) = new(l, r) + (::Type{ClosedInterval{T}}){T}(l::T, r::T) = new{T}(l, r) end ClosedInterval{T}(left::T, right::T) = ClosedInterval{T}(left, right) diff --git a/test/runtests.jl b/test/runtests.jl index 9013112..a9fda73 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -2,7 +2,6 @@ using IntervalSets using Base.Test @testset "IntervalSets" begin - io = IOBuffer() @test ordered(2, 1) == (1, 2) @test ordered(1, 2) == (1, 2) @test ordered(Float16(1), 2) == (1, 2) @@ -10,14 +9,12 @@ using Base.Test @testset "Closed Sets" begin @test_throws ArgumentError :a .. "b" I = 0..3 - print(io, I) - @test takebuf_string(io) == "0..3" + @test string(I) == "0..3" J = 3..2 K = 5..4 L = 3 ± 2 M = ClosedInterval(2, 5.0) - print(io, M) - @test takebuf_string(io) == "2.0..5.0" + @test string(M) == "2.0..5.0" N = ClosedInterval(UInt8(255), 300) O = CartesianIndex(1, 2, 3, 4) ± 2 @test O == (-1..3, 0..4, 1..5, 2..6)