You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: test/expr/cast/as_coerce.swift
+36-31Lines changed: 36 additions & 31 deletions
Original file line number
Diff line number
Diff line change
@@ -113,40 +113,45 @@ let s : AnyObject = C3()
113
113
s asC3 // expected-error{{'AnyObject' is not convertible to 'C3'}}
114
114
// expected-note@-1{{did you mean to use 'as!' to force downcast?}} {{3-5=as!}}
115
115
116
-
// SR-6022
117
-
func sr6022()->Any{return0}
118
-
func sr6022_1(){return; }
119
-
protocolSR6022_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
+
protocolP_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
+
}
135
151
}
136
152
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
148
154
149
-
// SR-13899
150
155
letany:Any=1
151
156
iflet int = any asInt{ // expected-error {{'Any' is not convertible to 'Int'}}
152
157
// expected-note@-1 {{did you mean to use 'as?' to conditionally downcast?}} {{18-20=as?}}
0 commit comments