Skip to content

Commit 41e94ac

Browse files
committed
stdlib: fix a bug in CountableClosedRange._customContainsEquatableElement() and add better tests for range types
The tests are still not thorough enough, but this is a start.
1 parent adb8ade commit 41e94ac

File tree

6 files changed

+433
-445
lines changed

6 files changed

+433
-445
lines changed

stdlib/public/core/ClosedRange.swift

+1-2
Original file line numberDiff line numberDiff line change
@@ -268,10 +268,9 @@ public struct CountableClosedRange<
268268

269269
@warn_unused_result
270270
public func _customContainsEquatableElement(_ element: Bound) -> Bool? {
271-
return element >= self.lowerBound && element < self.upperBound
271+
return element >= self.lowerBound && element <= self.upperBound
272272
}
273273

274-
275274
/// Returns `true` iff `self.contains(x)` is `false` for all values of `x`.
276275
public var isEmpty: Bool {
277276
return false

stdlib/public/core/Range.swift

+2-8
Original file line numberDiff line numberDiff line change
@@ -159,12 +159,6 @@ extension HalfOpenRangeProtocol {
159159
uncheckedBounds: (lower: other.lowerBound, upper: other.upperBound)
160160
)
161161
}
162-
163-
/// Returns `true` iff `lowerBound <= value && upperBound > value`.
164-
@inline(__always)
165-
public func contains(_ value: Bound) -> Bool {
166-
return lowerBound <= value && upperBound > value
167-
}
168162

169163
/// A textual representation of `self`.
170164
public var description: String {
@@ -326,7 +320,7 @@ public struct CountableRange<
326320

327321
@warn_unused_result
328322
public func _customContainsEquatableElement(_ element: Element) -> Bool? {
329-
return element >= self.lowerBound && element < self.upperBound
323+
return lowerBound <= element && element < upperBound
330324
}
331325

332326
/// Returns `true` iff `self.contains(x)` is `false` for all values of `x`.
@@ -507,7 +501,7 @@ public struct Range<
507501
/// `upperBound`.
508502
@warn_unused_result
509503
public func contains(_ element: Bound) -> Bool {
510-
return element >= self.lowerBound && element < self.upperBound
504+
return lowerBound <= element && element < upperBound
511505
}
512506

513507
/// Returns `true` iff `self.contains(x)` is `false` for all values of `x`.

test/1_stdlib/Interval.swift

-224
This file was deleted.

0 commit comments

Comments
 (0)