Skip to content

Commit ebabfe6

Browse files
committed
[stdlib] Remove optional comparison operators (SE-0121)
1 parent 6ad0f30 commit ebabfe6

File tree

5 files changed

+13
-53
lines changed

5 files changed

+13
-53
lines changed

stdlib/public/core/Optional.swift

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -380,44 +380,6 @@ public func != <T>(lhs: _OptionalNilComparisonType, rhs: T?) -> Bool {
380380
}
381381
}
382382

383-
public func < <T : Comparable>(lhs: T?, rhs: T?) -> Bool {
384-
switch (lhs, rhs) {
385-
case let (l?, r?):
386-
return l < r
387-
case (nil, _?):
388-
return true
389-
default:
390-
return false
391-
}
392-
}
393-
394-
public func > <T : Comparable>(lhs: T?, rhs: T?) -> Bool {
395-
switch (lhs, rhs) {
396-
case let (l?, r?):
397-
return l > r
398-
default:
399-
return rhs < lhs
400-
}
401-
}
402-
403-
public func <= <T : Comparable>(lhs: T?, rhs: T?) -> Bool {
404-
switch (lhs, rhs) {
405-
case let (l?, r?):
406-
return l <= r
407-
default:
408-
return !(rhs < lhs)
409-
}
410-
}
411-
412-
public func >= <T : Comparable>(lhs: T?, rhs: T?) -> Bool {
413-
switch (lhs, rhs) {
414-
case let (l?, r?):
415-
return l >= r
416-
default:
417-
return !(lhs < rhs)
418-
}
419-
}
420-
421383
/// Performs a nil-coalescing operation, returning the wrapped value of an
422384
/// `Optional` instance or a default value.
423385
///

test/1_stdlib/Optional.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ func testRelation(_ p: (Int?, Int?) -> Bool) -> [Bool] {
7373
OptionalTests.test("Equatable") {
7474
expectEqual([true, false, false, false, false, true], testRelation(==))
7575
expectEqual([false, true, true, true, true, false], testRelation(!=))
76-
expectEqual([false, true, false, false, true, false], testRelation(<))
7776
}
7877

7978
OptionalTests.test("CustomReflectable") {

test/1_stdlib/TestCalendar.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ class TestCalendar : TestCalendarSuper {
219219
// Find the days numbered '31' after 'd', allowing the algorithm to move to the next day if required
220220
c.enumerateDates(startingAfter: d, matching: DateComponents(day: 31), matchingPolicy: .nextTime) { result, exact, stop in
221221
// Just stop some arbitrary time in the future
222-
if result > d + 86400*365 { stop = true }
222+
if result! > d + 86400*365 { stop = true }
223223
count += 1
224224
if exact { exactCount += 1 }
225225
}

test/Constraints/diagnostics.swift

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -787,15 +787,14 @@ func nilComparison(i: Int, o: AnyObject) {
787787
_ = i != nil // expected-warning {{comparing non-optional value of type 'Int' to nil always returns true}}
788788
_ = nil != i // expected-warning {{comparing non-optional value of type 'Int' to nil always returns true}}
789789

790-
// These should all be illegal when SE-0121 lands.
791-
_ = i < nil
792-
_ = nil < i
793-
_ = i <= nil
794-
_ = nil <= i
795-
_ = i > nil
796-
_ = nil > i
797-
_ = i >= nil
798-
_ = nil >= i
790+
_ = i < nil // expected-error {{type 'Int' is not optional, value can never be nil}}
791+
_ = nil < i // expected-error {{type 'Int' is not optional, value can never be nil}}
792+
_ = i <= nil // expected-error {{type 'Int' is not optional, value can never be nil}}
793+
_ = nil <= i // expected-error {{type 'Int' is not optional, value can never be nil}}
794+
_ = i > nil // expected-error {{type 'Int' is not optional, value can never be nil}}
795+
_ = nil > i // expected-error {{type 'Int' is not optional, value can never be nil}}
796+
_ = i >= nil // expected-error {{type 'Int' is not optional, value can never be nil}}
797+
_ = nil >= i // expected-error {{type 'Int' is not optional, value can never be nil}}
799798

800799
_ = o === nil // expected-warning {{comparing non-optional value of type 'AnyObject' to nil always returns false}}
801800
_ = o !== nil // expected-warning {{comparing non-optional value of type 'AnyObject' to nil always returns true}}

test/Parse/try.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ i = try? foo() + bar()
4242
i ?+= try? foo() + bar()
4343
i ?+= try? foo() %%%% bar() // expected-error {{'try?' following assignment operator does not cover everything to its right}} // expected-error {{call can throw but is not marked with 'try'}} // expected-warning {{result of operator '%%%%' is unused}}
4444
i ?+= try? foo() %%% bar()
45-
_ = foo() < try? bar() // expected-error {{'try?' cannot appear to the right of a non-assignment operator}} // expected-error {{call can throw but is not marked with 'try'}}
46-
_ = (try? foo()) < bar() // expected-error {{call can throw but is not marked with 'try'}}
47-
_ = foo() < (try? bar()) // expected-error {{call can throw but is not marked with 'try'}}
48-
_ = (try? foo()) < (try? bar())
45+
_ = foo() == try? bar() // expected-error {{'try?' cannot appear to the right of a non-assignment operator}} // expected-error {{call can throw but is not marked with 'try'}}
46+
_ = (try? foo()) == bar() // expected-error {{call can throw but is not marked with 'try'}}
47+
_ = foo() == (try? bar()) // expected-error {{call can throw but is not marked with 'try'}}
48+
_ = (try? foo()) == (try? bar())
4949

5050
let j = true ? try? foo() : try? bar() + 0
5151
let k = true ? try? foo() : try? bar() %%% 0 // expected-error {{'try?' following conditional operator does not cover everything to its right}}

0 commit comments

Comments
 (0)