From 797f769e32e30a23706f3ccae38ad89ce3f62011 Mon Sep 17 00:00:00 2001 From: Rafael Fourquet Date: Tue, 24 Mar 2020 17:50:08 +0100 Subject: [PATCH] fix #35225, issubset on empty ranges (#35244) --- base/range.jl | 2 +- test/ranges.jl | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/base/range.jl b/base/range.jl index f56de9118174db..c836d94fe3a922 100644 --- a/base/range.jl +++ b/base/range.jl @@ -876,7 +876,7 @@ end issubset(r::OneTo, s::OneTo) = r.stop <= s.stop issubset(r::AbstractUnitRange{<:Integer}, s::AbstractUnitRange{<:Integer}) = - first(r) >= first(s) && last(r) <= last(s) + isempty(r) || first(r) >= first(s) && last(r) <= last(s) ## linear operations on ranges ## diff --git a/test/ranges.jl b/test/ranges.jl index fdcda964734541..988af1c7c29107 100644 --- a/test/ranges.jl +++ b/test/ranges.jl @@ -387,6 +387,11 @@ end @test !issubset(Base.OneTo(10), Base.OneTo(5)) @test issubset(1:3:10, 1:10) @test !issubset(1:10, 1:3:10) + # with empty ranges + @test issubset(2:1, 3:4) #35225 + @test issubset(2:1, 3:2) + @test issubset(Base.OneTo(0), Base.OneTo(3)) + @test issubset(Base.OneTo(0), Base.OneTo(-3)) end @testset "sort/sort!/partialsort" begin @test sort(UnitRange(1,2)) == UnitRange(1,2)