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/Constraints/bridging.swift
+15-11Lines changed: 15 additions & 11 deletions
Original file line number
Diff line number
Diff line change
@@ -276,30 +276,34 @@ func rdar19831698() {
276
276
// <rdar://problem/19836341> Incorrect fixit for NSString? to String? conversions
277
277
func rdar19836341(_ ns:NSString?, vns:NSString?){
278
278
varvns= vns
279
-
let _:String?= ns // expected-error{{cannot convert value of type 'NSString?' to specified type 'String?'}}
280
-
var _:String?= ns // expected-error{{cannot convert value of type 'NSString?' to specified type 'String?'}}
281
-
// FIXME: there should be a fixit appending "as String?" to the line; for now
282
-
// it's sufficient that it doesn't suggest appending "as String"
279
+
let _:String?= ns // expected-error{{cannot convert value of type 'NSString?' to specified type 'String?'}}{{22-22= as String?}}
280
+
var _:String?= ns // expected-error{{cannot convert value of type 'NSString?' to specified type 'String?'}}{{22-22= as String?}}
283
281
284
282
// Important part about below diagnostic is that from-type is described as
285
283
// 'NSString?' and not '@lvalue NSString?':
286
-
let _:String?= vns // expected-error{{cannot convert value of type 'NSString?' to specified type 'String?'}}
287
-
var _:String?= vns // expected-error{{cannot convert value of type 'NSString?' to specified type 'String?'}}
288
-
284
+
let _:String?= vns // expected-error{{cannot convert value of type 'NSString?' to specified type 'String?'}}{{23-23= as String?}}
285
+
var _:String?= vns // expected-error{{cannot convert value of type 'NSString?' to specified type 'String?'}}{{23-23= as String?}}
286
+
289
287
vns = ns
290
288
}
291
289
292
290
// <rdar://problem/20029786> Swift compiler sometimes suggests changing "as!" to "as?!"
293
291
func rdar20029786(_ ns:NSString?){
294
-
vars:String= ns ??"str"asStringasString // expected-error{{cannot convert value of type 'NSString?' to expected argument type 'String?'}}
295
-
vars2= ns ??"str"asStringasString // expected-error {{cannot convert value of type 'String' to expected argument type 'NSString'}}
292
+
vars:String= ns ??"str"asStringasString // expected-error{{cannot convert value of type 'NSString?' to expected argument type 'String?'}}{{21-21= as String?}}
293
+
vars2= ns ??"str"asStringasString // expected-error {{cannot convert value of type 'String' to expected argument type 'NSString'}}{{43-43= as NSString}}
296
294
297
-
lets3:NSString?="str"asString? // expected-error {{cannot convert value of type 'String?' to specified type 'NSString?'}}
295
+
lets3:NSString?="str"asString? // expected-error {{cannot convert value of type 'String?' to specified type 'NSString?'}}{{39-39= as NSString?}}
298
296
299
-
vars4:String= ns ??"str" // expected-error{{cannot convert value of type 'NSString' to specified type 'String'}}
297
+
vars4:String= ns ??"str" // expected-error{{cannot convert value of type 'NSString' to specified type 'String'}}{{31-31= as String}}
300
298
vars5:String=(ns ??"str")asString // fixed version
301
299
}
302
300
301
+
// Make sure more complicated cast has correct parenthesization
302
+
func castMoreComplicated(anInt:Int?){
303
+
let _:(NSObject&NSCopying)?= anInt // expected-error{{cannot convert value of type 'Int?' to specified type '(NSObject & NSCopying)?'}}{{41-41= as (NSObject & NSCopying)?}}
304
+
}
305
+
306
+
303
307
// <rdar://problem/19813772> QoI: Using as! instead of as in this case produces really bad diagnostic
304
308
func rdar19813772(_ nsma:NSMutableArray){
305
309
vara1= nsma as!Array // expected-error{{generic parameter 'Element' could not be inferred in cast to 'Array'}} expected-note {{explicitly specify the generic arguments to fix this issue}} {{26-26=<Any>}}
0 commit comments