diff --git a/stdlib/public/core/Interval.swift.gyb b/stdlib/public/core/Interval.swift.gyb index 1cea2aa380d6a..1f9a0af10c1e4 100644 --- a/stdlib/public/core/Interval.swift.gyb +++ b/stdlib/public/core/Interval.swift.gyb @@ -167,12 +167,13 @@ extension ClosedInterval { } extension IntervalType { - /// Returns `true` if `lhs` and `rhs` have a non-empty intersection. + /// Returns `true` iff `lhs` and `rhs` have a non-empty intersection. @warn_unused_result public func overlaps< I: IntervalType where I.Bound == Bound >(other: I) -> Bool { - return contains(other.start) || other.contains(start) + return (!other.isEmpty && contains(other.start)) + || (!isEmpty && other.contains(start)) } } diff --git a/test/1_stdlib/Interval.swift b/test/1_stdlib/Interval.swift index 38679fc2be2e3..dc1c8396cee1d 100644 --- a/test/1_stdlib/Interval.swift +++ b/test/1_stdlib/Interval.swift @@ -131,6 +131,11 @@ IntervalTestSuite.test("Overlaps") { expectOverlaps(true, 0..<20, 5...10) expectOverlaps(true, 0...20, 5..<10) expectOverlaps(true, 0...20, 5...10) + + // 0-0, 0-5 + expectOverlaps(false, 0..<0, 0..<5) + expectOverlaps(false, 0..<0, 0...5) + } IntervalTestSuite.test("Emptiness") {