@@ -139,7 +139,7 @@ func checkMethodCalls() {
139
139
takeMaybe ( true ? . none : . just( MO ( ) ) ) // expected-error 3{{move-only type 'MO' cannot be used with generics yet}}
140
140
}
141
141
142
- func checkCasting( _ b: any Box , _ mo: MO ) {
142
+ func checkCasting( _ b: any Box , _ mo: MO , _ a : Any ) {
143
143
// casting dynamically is allowed, but should always fail since you can't
144
144
// construct such a type.
145
145
let box = b as! ValBox < MO > // expected-error {{move-only type 'MO' cannot be used with generics yet}}
@@ -159,26 +159,65 @@ func checkCasting(_ b: any Box, _ mo: MO) {
159
159
_ = MO ( ) as Any // expected-error {{move-only type 'MO' cannot be used with generics yet}}
160
160
_ = MO ( ) as MO
161
161
_ = MO ( ) as AnyObject // expected-error {{move-only type 'MO' cannot be used with generics yet}}
162
+ _ = 5 as MO // expected-error {{cannot convert value of type 'Int' to type 'MO' in coercion}}
163
+ _ = a as MO // expected-error {{cannot convert value of type 'Any' to type 'MO' in coercion}}
164
+ _ = b as MO // expected-error {{cannot convert value of type 'any Box' to type 'MO' in coercion}}
162
165
163
166
// FIXME(kavon): make sure at runtime these casts actually fail, or just make them errors? (rdar://104900293)
164
167
165
168
_ = MO ( ) is AnyHashable // expected-warning {{cast from 'MO' to unrelated type 'AnyHashable' always fails}}
169
+ // expected-error@-1 {{move-only types cannot be conditionally cast}}
166
170
_ = MO ( ) is AnyObject // expected-warning {{cast from 'MO' to unrelated type 'AnyObject' always fails}}
171
+ // expected-error@-1 {{move-only types cannot be conditionally cast}}
167
172
_ = MO ( ) is Any // expected-warning {{cast from 'MO' to unrelated type 'Any' always fails}}
173
+ // expected-error@-1 {{move-only types cannot be conditionally cast}}
168
174
_ = MO ( ) is P // expected-warning {{cast from 'MO' to unrelated type 'any P' always fails}}
175
+ // expected-error@-1 {{move-only types cannot be conditionally cast}}
169
176
_ = MO ( ) is MO // expected-warning {{'is' test is always true}}
177
+ // expected-error@-1 {{move-only types cannot be conditionally cast}}
178
+
179
+ _ = 5 is MO // expected-warning {{cast from 'Int' to unrelated type 'MO' always fails}}
180
+ // expected-error@-1 {{move-only types cannot be conditionally cast}}
181
+ _ = a is MO // expected-warning {{cast from 'Any' to unrelated type 'MO' always fails}}
182
+ // expected-error@-1 {{move-only types cannot be conditionally cast}}
183
+ _ = b is MO // expected-warning {{cast from 'any Box' to unrelated type 'MO' always fails}}
184
+ // expected-error@-1 {{move-only types cannot be conditionally cast}}
170
185
171
186
_ = MO ( ) as! AnyHashable // expected-warning {{cast from 'MO' to unrelated type 'AnyHashable' always fails}}
187
+ // expected-error@-1 {{move-only types cannot be conditionally cast}}
172
188
_ = MO ( ) as! AnyObject // expected-warning {{cast from 'MO' to unrelated type 'AnyObject' always fails}}
189
+ // expected-error@-1 {{move-only types cannot be conditionally cast}}
173
190
_ = MO ( ) as! Any // expected-warning {{cast from 'MO' to unrelated type 'Any' always fails}}
191
+ // expected-error@-1 {{move-only types cannot be conditionally cast}}
174
192
_ = MO ( ) as! P // expected-warning {{cast from 'MO' to unrelated type 'any P' always fails}}
193
+ // expected-error@-1 {{move-only types cannot be conditionally cast}}
175
194
_ = MO ( ) as! MO // expected-warning {{forced cast of 'MO' to same type has no effect}}
195
+ // expected-error@-1 {{move-only types cannot be conditionally cast}}
196
+
197
+ _ = 5 as! MO // expected-warning {{cast from 'Int' to unrelated type 'MO' always fails}}
198
+ // expected-error@-1 {{move-only types cannot be conditionally cast}}
199
+ _ = a as! MO // expected-warning {{cast from 'Any' to unrelated type 'MO' always fails}}
200
+ // expected-error@-1 {{move-only types cannot be conditionally cast}}
201
+ _ = b as! MO // expected-warning {{cast from 'any Box' to unrelated type 'MO' always fails}}
202
+ // expected-error@-1 {{move-only types cannot be conditionally cast}}
176
203
177
204
_ = MO ( ) as? AnyHashable // expected-warning {{cast from 'MO' to unrelated type 'AnyHashable' always fails}}
205
+ // expected-error@-1 {{move-only types cannot be conditionally cast}}
178
206
_ = MO ( ) as? AnyObject // expected-warning {{cast from 'MO' to unrelated type 'AnyObject' always fails}}
207
+ // expected-error@-1 {{move-only types cannot be conditionally cast}}
179
208
_ = MO ( ) as? Any // expected-warning {{cast from 'MO' to unrelated type 'Any' always fails}}
209
+ // expected-error@-1 {{move-only types cannot be conditionally cast}}
180
210
_ = MO ( ) as? P // expected-warning {{cast from 'MO' to unrelated type 'any P' always fails}}
211
+ // expected-error@-1 {{move-only types cannot be conditionally cast}}
181
212
_ = MO ( ) as? MO // expected-warning {{conditional cast from 'MO' to 'MO' always succeeds}}
213
+ // expected-error@-1 {{move-only types cannot be conditionally cast}}
214
+
215
+ _ = 5 as? MO // expected-warning {{cast from 'Int' to unrelated type 'MO' always fails}}
216
+ // expected-error@-1 {{move-only types cannot be conditionally cast}}
217
+ _ = a as? MO // expected-warning {{cast from 'Any' to unrelated type 'MO' always fails}}
218
+ // expected-error@-1 {{move-only types cannot be conditionally cast}}
219
+ _ = b as? MO // expected-warning {{cast from 'any Box' to unrelated type 'MO' always fails}}
220
+ // expected-error@-1 {{move-only types cannot be conditionally cast}}
182
221
183
222
}
184
223
0 commit comments