Skip to content

Commit 88b65f4

Browse files
committed
Update tests
1 parent ded9b78 commit 88b65f4

File tree

4 files changed

+20
-0
lines changed

4 files changed

+20
-0
lines changed

test/ClangImporter/nullability.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ func testSomeClass(_ sc: SomeClass, osc: SomeClass?) {
66
let ao1: Any = sc.methodA(osc)
77
_ = ao1
88
if sc.methodA(osc) == nil { } // expected-warning {{comparing non-optional value of type 'Any' to 'nil' always returns false}}
9+
if sc.methodA(osc) == Optional.none { } // expected-warning {{comparing non-optional value of type 'Any' to 'Optional.none' always returns false}}
910

1011
let ao2: Any = sc.methodB(nil)
1112
_ = ao2

test/Constraints/diagnostics.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -746,9 +746,13 @@ class C_44203 {
746746
_ = (i === nil) // expected-error {{value of type 'Int?' cannot be compared by reference; did you mean to compare by value?}} {{12-15===}}
747747
_ = (bytes === nil) // expected-error {{type 'UnsafeMutablePointer<Int>' is not optional, value can never be nil}}
748748
_ = (self === nil) // expected-warning {{comparing non-optional value of type 'AnyObject' to 'nil' always returns false}}
749+
_ = (self === .none) // expected-warning {{comparing non-optional value of type 'AnyObject' to 'Optional.none' always returns false}}
750+
_ = (self === Optional.none) // expected-warning {{comparing non-optional value of type 'AnyObject' to 'Optional.none' always returns false}}
749751
_ = (i !== nil) // expected-error {{value of type 'Int?' cannot be compared by reference; did you mean to compare by value?}} {{12-15=!=}}
750752
_ = (bytes !== nil) // expected-error {{type 'UnsafeMutablePointer<Int>' is not optional, value can never be nil}}
751753
_ = (self !== nil) // expected-warning {{comparing non-optional value of type 'AnyObject' to 'nil' always returns true}}
754+
_ = (self !== .none) // expected-warning {{comparing non-optional value of type 'AnyObject' to 'Optional.none' always returns true}}
755+
_ = (self !== Optional.none) // expected-warning {{comparing non-optional value of type 'AnyObject' to 'Optional.none' always returns true}}
752756
}
753757
}
754758

@@ -757,6 +761,11 @@ func nilComparison(i: Int, o: AnyObject) {
757761
_ = nil == i // expected-warning {{comparing non-optional value of type 'Int' to 'nil' always returns false}}
758762
_ = i != nil // expected-warning {{comparing non-optional value of type 'Int' to 'nil' always returns true}}
759763
_ = nil != i // expected-warning {{comparing non-optional value of type 'Int' to 'nil' always returns true}}
764+
765+
_ = i == Optional.none // expected-warning {{comparing non-optional value of type 'Int' to 'Optional.none' always returns false}}
766+
_ = Optional.none == i // expected-warning {{comparing non-optional value of type 'Int' to 'Optional.none' always returns false}}
767+
_ = i != Optional.none // expected-warning {{comparing non-optional value of type 'Int' to 'Optional.none' always returns true}}
768+
_ = Optional.none != i // expected-warning {{comparing non-optional value of type 'Int' to 'Optional.none' always returns true}}
760769

761770
// FIXME(integers): uncomment these tests once the < is no longer ambiguous
762771
// _ = i < nil // _xpected-error {{type 'Int' is not optional, value can never be nil}}

test/expr/cast/nil_value_to_optional.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ func markUsed<T>(_ t: T) {}
77

88
markUsed(t != nil) // expected-warning {{comparing non-optional value of type 'Bool' to 'nil' always returns true}}
99
markUsed(f != nil) // expected-warning {{comparing non-optional value of type 'Bool' to 'nil' always returns true}}
10+
markUsed(t != Optional.none) // expected-warning {{comparing non-optional value of type 'Bool' to 'Optional.none' always returns true}}
11+
markUsed(f != Optional.none) // expected-warning {{comparing non-optional value of type 'Bool' to 'Optional.none' always returns true}}
1012

1113
class C : Equatable {}
1214

@@ -16,6 +18,9 @@ func == (lhs: C, rhs: C) -> Bool {
1618

1719
func test(_ c: C) {
1820
if c == nil {} // expected-warning {{comparing non-optional value of type 'C' to 'nil' always returns false}}
21+
if c == .none {} // expected-warning {{comparing non-optional value of type 'C' to 'Optional.none' always returns false}}
22+
if c == Optional.none {} // expected-warning {{comparing non-optional value of type 'C' to 'Optional.none' always returns false}}
23+
if c == C?.none {} // expected-warning {{comparing non-optional value of type 'C' to 'Optional.none' always returns false}}
1924
}
2025

2126
class D {}

test/expr/expressions.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -767,6 +767,11 @@ _ = nil == Int.self // expected-warning {{comparing non-optional value of type
767767
_ = Int.self != nil // expected-warning {{comparing non-optional value of type 'any Any.Type' to 'nil' always returns true}}
768768
_ = nil != Int.self // expected-warning {{comparing non-optional value of type 'any Any.Type' to 'nil' always returns true}}
769769

770+
_ = Int.self == .none // expected-warning {{comparing non-optional value of type 'any Any.Type' to 'Optional.none' always returns false}}
771+
_ = .none == Int.self // expected-warning {{comparing non-optional value of type 'any Any.Type' to 'Optional.none' always returns false}}
772+
_ = Int.self != .none // expected-warning {{comparing non-optional value of type 'any Any.Type' to 'Optional.none' always returns true}}
773+
_ = .none != Int.self // expected-warning {{comparing non-optional value of type 'any Any.Type' to 'Optional.none' always returns true}}
774+
770775
// <rdar://problem/19032294> Disallow postfix ? when not chaining
771776
func testOptionalChaining(_ a : Int?, b : Int!, c : Int??) {
772777
_ = a? // expected-error {{optional chain has no effect, expression already produces 'Int?'}} {{8-9=}}

0 commit comments

Comments
 (0)