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
[CSSimplify] Detect when generic argument mismatch applies to argument and produce a tailed fix
The problem detection logic currently expects `generic argument #<N>`
location to always be associated with two generic types, but that
is not always the case, this locator element is sometimes used for
i.e. optional object types and pointer `Pointee` type when types
appear in argument positions. This needs to be handled specifically.
Resolves: rdar://82971941
(cherry picked from commit ded6158)
// <rdar://problem/20029786> Swift compiler sometimes suggests changing "as!" to "as?!"
298
298
func rdar20029786(_ ns:NSString?){
299
-
vars:String= ns ??"str"asStringasString // expected-error{{'NSString' is not implicitly convertible to 'String'; did you mean to use 'as' to explicitly convert?}} {{19-19=(}} {{50-50=) as String}}
300
-
// expected-error@-1 {{cannot convert value of type 'String' to expected argument type 'NSString'}} {{50-50= as NSString}}
301
-
vars2= ns ??"str"asStringasString // expected-error {{cannot convert value of type 'String' to expected argument type 'NSString'}}{{43-43= as NSString}}
299
+
vars:String= ns ??"str"asStringasString
300
+
// expected-error@-1 {{cannot convert value of type 'NSString?' to expected argument type 'String?'}} {{21-21= as String?}}
301
+
vars2= ns ??"str"asStringasString // expected-error {{binary operator '??' cannot be applied to operands of type 'NSString?' and 'String'}}
302
302
303
303
lets3:NSString?="str"asString? // expected-error {{cannot convert value of type 'String?' to specified type 'NSString?'}}{{39-39= as NSString?}}
_ =UnsafeMutablePointer<Int>(rp) // expected-error {{cannot convert value of type 'UnsafeRawPointer' to expected argument type 'UnsafeMutablePointer<Int>'}}
80
80
_ =UnsafeMutablePointer<Int>(mrp) // expected-error {{cannot convert value of type 'UnsafeMutableRawPointer' to expected argument type 'UnsafeMutablePointer<Int>'}}
81
-
// Two candidates here: OpaquePointer? and UnsafeMutablePointer<Int>?
81
+
// This is ambiguous because we have failable and non-failable initializers that accept the same argument type.
82
82
_ =UnsafeMutablePointer<Int>(orp) // expected-error {{no exact matches in call to initializer}}
83
-
// Two candidates here: OpaquePointer? and UnsafeMutablePointer<Int>?
84
-
_ =UnsafeMutablePointer<Int>(omrp) // expected-error {{no exact matches in call to initializer}}
83
+
_ =UnsafeMutablePointer<Int>(omrp) // expected-error {{cannot convert value of type 'UnsafeMutableRawPointer' to expected argument type 'UnsafeMutablePointer<Int>'}}
85
84
86
85
_ =UnsafePointer<Int>(rp) // expected-error {{cannot convert value of type 'UnsafeRawPointer' to expected argument type 'UnsafePointer<Int>'}}
87
86
_ =UnsafePointer<Int>(mrp) // expected-error {{cannot convert value of type 'UnsafeMutableRawPointer' to expected argument type 'UnsafePointer<Int>'}}
88
-
// Two candidates here: OpaquePointer? and UnsafeMutablePointer<Int>?
89
-
_ =UnsafePointer<Int>(orp) // expected-error {{no exact matches in call to initializer}}
90
-
// Two candidates here: OpaquePointer? and UnsafeMutablePointer<Int>?
91
-
_ =UnsafePointer<Int>(omrp) // expected-error {{no exact matches in call to initializer}}
87
+
_ =UnsafePointer<Int>(orp) // expected-error {{cannot convert value of type 'UnsafeRawPointer' to expected argument type 'UnsafePointer<Int>'}}
88
+
_ =UnsafePointer<Int>(omrp) // expected-error {{cannot convert value of type 'UnsafeMutableRawPointer' to expected argument type 'UnsafePointer<Int>'}}
92
89
93
90
_ =UnsafePointer<Int>(ups) // expected-error {{cannot convert value of type 'UnsafePointer<String>' to expected argument type 'UnsafePointer<Int>'}}
94
91
// expected-note@-1 {{arguments to generic parameter 'Pointee' ('String' and 'Int') are expected to be equal}}
0 commit comments