Skip to content

Commit 5324bf9

Browse files
committed
Gardening: Migrate test suite to GH issues: expr/cast
1 parent 45f5f08 commit 5324bf9

File tree

3 files changed

+44
-37
lines changed

3 files changed

+44
-37
lines changed

test/expr/cast/as_coerce.swift

Lines changed: 36 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -113,40 +113,45 @@ let s : AnyObject = C3()
113113
s as C3 // expected-error{{'AnyObject' is not convertible to 'C3'}}
114114
// expected-note@-1{{did you mean to use 'as!' to force downcast?}} {{3-5=as!}}
115115

116-
// SR-6022
117-
func sr6022() -> Any { return 0 }
118-
func sr6022_1() { return; }
119-
protocol SR6022_P {}
120-
121-
_ = sr6022 is SR6022_P // expected-warning {{cast from '() -> Any' to unrelated type 'any SR6022_P' always fails}} // expected-note {{did you mean to call 'sr6022' with '()'?}}{{11-11=()}}
122-
_ = sr6022 as! SR6022_P // expected-warning {{cast from '() -> Any' to unrelated type 'any SR6022_P' always fails}} // expected-note {{did you mean to call 'sr6022' with '()'?}}{{11-11=()}}
123-
_ = sr6022 as? SR6022_P // expected-warning {{cast from '() -> Any' to unrelated type 'any SR6022_P' always fails}} // expected-note {{did you mean to call 'sr6022' with '()'}}{{11-11=()}}
124-
_ = sr6022_1 is SR6022_P // expected-warning {{cast from '() -> ()' to unrelated type 'any SR6022_P' always fails}}
125-
_ = sr6022_1 as! SR6022_P // expected-warning {{cast from '() -> ()' to unrelated type 'any SR6022_P' always fails}}
126-
_ = sr6022_1 as? SR6022_P // expected-warning {{cast from '() -> ()' to unrelated type 'any SR6022_P' always fails}}
127-
128-
func testSR6022_P<T: SR6022_P>(_: T.Type) {
129-
_ = sr6022 is T // expected-warning {{cast from '() -> Any' to unrelated type 'T' always fails}} // expected-note {{did you mean to call 'sr6022' with '()'?}}{{13-13=()}}
130-
_ = sr6022 as! T // expected-warning {{cast from '() -> Any' to unrelated type 'T' always fails}} // expected-note {{did you mean to call 'sr6022' with '()'?}}{{13-13=()}}
131-
_ = sr6022 as? T // expected-warning {{cast from '() -> Any' to unrelated type 'T' always fails}} // expected-note {{did you mean to call 'sr6022' with '()'?}}{{13-13=()}}
132-
_ = sr6022_1 is T // expected-warning {{cast from '() -> ()' to unrelated type 'T' always fails}}
133-
_ = sr6022_1 as! T // expected-warning {{cast from '() -> ()' to unrelated type 'T' always fails}}
134-
_ = sr6022_1 as? T // expected-warning {{cast from '() -> ()' to unrelated type 'T' always fails}}
116+
// https://github.com/apple/swift/issues/48579
117+
118+
protocol P_48579 {}
119+
do {
120+
func f1() -> Any {}
121+
func f2() {}
122+
123+
_ = f1 is P_48579 // expected-warning {{cast from '() -> Any' to unrelated type 'any P_48579' always fails}} // expected-note {{did you mean to call 'f1' with '()'?}}{{9-9=()}}
124+
_ = f1 as! P_48579 // expected-warning {{cast from '() -> Any' to unrelated type 'any P_48579' always fails}} // expected-note {{did you mean to call 'f1' with '()'?}}{{9-9=()}}
125+
_ = f1 as? P_48579 // expected-warning {{cast from '() -> Any' to unrelated type 'any P_48579' always fails}} // expected-note {{did you mean to call 'f1' with '()'}}{{9-9=()}}
126+
_ = f2 is P_48579 // expected-warning {{cast from '() -> ()' to unrelated type 'any P_48579' always fails}}
127+
_ = f2 as! P_48579 // expected-warning {{cast from '() -> ()' to unrelated type 'any P_48579' always fails}}
128+
_ = f2 as? P_48579 // expected-warning {{cast from '() -> ()' to unrelated type 'any P_48579' always fails}}
129+
130+
_ = f1 as! AnyObject // expected-warning {{forced cast from '() -> Any' to 'AnyObject' always succeeds; did you mean to use 'as'?}}
131+
_ = f1 as? AnyObject // expected-warning {{conditional cast from '() -> Any' to 'AnyObject' always succeeds}}
132+
_ = f2 as! Any // expected-warning {{forced cast from '() -> ()' to 'Any' always succeeds; did you mean to use 'as'?}}
133+
_ = f2 as? Any // expected-warning {{conditional cast from '() -> ()' to 'Any' always succeeds}}
134+
135+
136+
func test1<T: P_48579>(_: T.Type) {
137+
_ = f1 is T // expected-warning {{cast from '() -> Any' to unrelated type 'T' always fails}} // expected-note {{did you mean to call 'f1' with '()'?}}{{11-11=()}}
138+
_ = f1 as! T // expected-warning {{cast from '() -> Any' to unrelated type 'T' always fails}} // expected-note {{did you mean to call 'f1' with '()'?}}{{11-11=()}}
139+
_ = f1 as? T // expected-warning {{cast from '() -> Any' to unrelated type 'T' always fails}} // expected-note {{did you mean to call 'f1' with '()'?}}{{11-11=()}}
140+
_ = f2 is T // expected-warning {{cast from '() -> ()' to unrelated type 'T' always fails}}
141+
_ = f2 as! T // expected-warning {{cast from '() -> ()' to unrelated type 'T' always fails}}
142+
_ = f2 as? T // expected-warning {{cast from '() -> ()' to unrelated type 'T' always fails}}
143+
}
144+
145+
func test2<U>(_: U.Type) {
146+
_ = f1 as! U // Okay
147+
_ = f1 as? U // Okay
148+
_ = f2 as! U // Okay
149+
_ = f2 as? U // Okay
150+
}
135151
}
136152

137-
func testSR6022_P_1<U>(_: U.Type) {
138-
_ = sr6022 as! U // Okay
139-
_ = sr6022 as? U // Okay
140-
_ = sr6022_1 as! U // Okay
141-
_ = sr6022_1 as? U // Okay
142-
}
143-
144-
_ = sr6022 as! AnyObject // expected-warning {{forced cast from '() -> Any' to 'AnyObject' always succeeds; did you mean to use 'as'?}}
145-
_ = sr6022 as? AnyObject // expected-warning {{conditional cast from '() -> Any' to 'AnyObject' always succeeds}}
146-
_ = sr6022_1 as! Any // expected-warning {{forced cast from '() -> ()' to 'Any' always succeeds; did you mean to use 'as'?}}
147-
_ = sr6022_1 as? Any // expected-warning {{conditional cast from '() -> ()' to 'Any' always succeeds}}
153+
// https://github.com/apple/swift/issues/56297
148154

149-
// SR-13899
150155
let any: Any = 1
151156
if let int = any as Int { // expected-error {{'Any' is not convertible to 'Int'}}
152157
// expected-note@-1 {{did you mean to use 'as?' to conditionally downcast?}} {{18-20=as?}}

test/expr/cast/metatype_casts.swift

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,11 @@ use(C.self as P.Type) // expected-error{{cannot convert value of type 'C.Type' t
5050
use(E.self as P.Protocol) // expected-error{{cannot convert value of type 'E.Type' to type '(any P).Type' in coercion}}
5151
use(E.self as P.Type)
5252

53-
// SR-12946
54-
func SR12946<T>(_ e: T) {
55-
_ = AnyObject.self is T.Type // OK
56-
}
53+
// https://github.com/apple/swift/issues/55392
54+
do {
55+
func f<T>(_ e: T) {
56+
_ = AnyObject.self is T.Type // OK
57+
}
5758

58-
SR12946(1 as AnyObject)
59+
f(1 as AnyObject)
60+
}

test/expr/cast/optional.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func implicitCastOfLiteralToOptional() {
4242
}
4343

4444
// A nil value can be cast to any other optional type.
45-
// https://bugs.swift.org/browse/SR-3505
45+
// https://github.com/apple/swift/issues/46093
4646
func castUnrelatedOptionalTypes(x: Int?) {
4747
let _ = x as String? // expected-error {{cannot convert value}}
4848
let _ = x as? String? // no-warning

0 commit comments

Comments
 (0)