Skip to content

Commit 46ec002

Browse files
authored
Allow in with mixed types (#61)
1 parent 4bee459 commit 46ec002

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

src/interval.jl

+6-1
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,12 @@ true
243243
##### SET OPERATIONS #####
244244

245245
Base.isempty(i::AbstractInterval) = LeftEndpoint(i) > RightEndpoint(i)
246-
Base.in(a::T, b::AbstractInterval{T}) where T = !(a b || a b)
246+
Base.in(a, b::AbstractInterval) = !(a b || a b)
247+
248+
function Base.in(a::AbstractInterval, b::AbstractInterval)
249+
# Intervals should be compared with set operations
250+
throw(ArgumentError("Intervals can not be compared with `in`. Use `issubset` instead."))
251+
end
247252

248253
function Base.issubset(a::AbstractInterval, b::AbstractInterval)
249254
return LeftEndpoint(a) LeftEndpoint(b) && RightEndpoint(a) RightEndpoint(b)

test/interval.jl

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
@testset "Interval" begin
22
test_values = [
33
(-10, 1000, 1),
4+
(0.0, 1, 0.01), # Use different types to test promotion
45
('a', 'z', 1),
56
(Date(2013, 2, 13), Date(2013, 3, 13), Day(1)),
67
(DateTime(2016, 8, 11, 0, 30), DateTime(2016, 8, 11, 1), Millisecond(1))
@@ -384,7 +385,7 @@
384385
@test in(b - unit, interval)
385386
@test !in(b + unit, interval)
386387

387-
@test_throws MethodError (in(Interval(a, b), Interval(a, b)))
388+
@test_throws ArgumentError (in(Interval(a, b), Interval(a, b)))
388389
end
389390
end
390391

0 commit comments

Comments
 (0)