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
[Diagnostics|SR-5789] Fixits for applying subscripts by keyword (#16431)
* [Diagnostics|SR-5789] Added fixits for referring to subscripts by keyword
If there is a subscript member, the error message changes to [type -bash has no member property or method named 'subscript']
The fix-it replaces parentheses with brackets, removes '.subscript'
If the apply expression is incomplete, e.g. subscript(..., the fix-it adds a bracket at the end.
* tests updated & logic for compatible arg types (except generics)
* ignore generic types & switch to returning
* avoid explicitly using sting literals
* handle implicit conversion of tuples & encapsulate it
* isolate subscript misusage
* return bool instead of void
* move function to FailureDiagnosis, diagnose independently & update error message
* Update CSDiag.cpp
// expected-error@-1 {{value of type 'GenSubscriptFixitTest' has no property or method named 'subscript'; did you mean to use the subscript operator?}} {{9-10=}} {{10-19=}} {{19-20=[}} {{27-28=]}}
265
+
}
266
+
249
267
structSubscriptTest1{
250
268
subscript(keyword:String)->Bool{returntrue} // expected-note 2 {{found this candidate}}
251
269
subscript(keyword:String)->String?{returnnil} // expected-note 2 {{found this candidate}}
let _ :Int=s1["hello"] // expected-error {{ambiguous subscript with base type 'SubscriptTest1' and index type 'String'}}
256
-
280
+
257
281
ifs1["hello"]{}
258
-
259
-
260
-
let _ =s1["hello"] // expected-error {{ambiguous use of 'subscript'}}
282
+
283
+
_ = s1.subscript((true,(5,SubClass())),"hello")
284
+
// expected-error@-1 {{value of type 'SubscriptTest1' has no property or method named 'subscript'; did you mean to use the subscript operator?}} {{9-10=}} {{10-19=}} {{19-20=[}} {{52-53=]}}
// expected-error@-1 {{value of type 'SubscriptTest1' has no property or method named 'subscript'; did you mean to use the subscript operator?}} {{9-10=}} {{10-19=}} {{19-20=[}} {{60-61=]}}
// expected-error@-1 {{value of type 'SubscriptTest1' has no property or method named 'subscript'; did you mean to use the subscript operator?}}
289
+
_ = s1.subscript(SubSubClass())
290
+
// expected-error@-1 {{value of type 'SubscriptTest1' has no property or method named 'subscript'; did you mean to use the subscript operator?}} {{9-10=}} {{10-19=}} {{19-20=[}} {{33-34=]}}
291
+
_ = s1.subscript(ClassConformingToProtocol())
292
+
// expected-error@-1 {{value of type 'SubscriptTest1' has no property or method named 'subscript'; did you mean to use the subscript operator?}} {{9-10=}} {{10-19=}} {{19-20=[}} {{47-48=]}}
// expected-error@-1 {{value of type 'SubscriptTest1' has no property or method named 'subscript'; did you mean to use the subscript operator?}} {{9-10=}} {{10-19=}} {{19-20=[}} {{54-55=]}}
295
+
_ = s1.subscript(true)
296
+
// expected-error@-1 {{value of type 'SubscriptTest1' has no property or method named 'subscript'; did you mean to use the subscript operator?}}
297
+
_ = s1.subscript(SuperClass())
298
+
// expected-error@-1 {{value of type 'SubscriptTest1' has no property or method named 'subscript'; did you mean to use the subscript operator?}}
299
+
_ = s1.subscript("hello")
300
+
// expected-error@-1 {{value of type 'SubscriptTest1' has no property or method named 'subscript'; did you mean to use the subscript operator?}} {{9-10=}} {{10-19=}} {{19-20=[}} {{27-28=]}}
301
+
_ = s1.subscript("hello"
302
+
// expected-error@-1 {{value of type 'SubscriptTest1' has no property or method named 'subscript'; did you mean to use the subscript operator?}} {{9-10=}} {{10-19=}} {{19-20=[}} {{27-27=]}}
303
+
// expected-note@-2 {{to match this opening '('}}
304
+
305
+
let _ =s1["hello"]
306
+
// expected-error@-1 {{ambiguous use of 'subscript'}}
307
+
// expected-error@-2 {{expected ')' in expression list}}
261
308
}
262
309
263
310
structSubscriptTest2{
264
311
subscript(a :String, b :Int)->Int{return0}
312
+
// expected-note@-1 {{declared here}}
265
313
subscript(a :String, b :String)->Int{return0}
266
314
}
267
315
268
316
func testSubscript1(_ s2 :SubscriptTest2){
269
317
_ =s2["foo"] // expected-error {{cannot subscript a value of type 'SubscriptTest2' with an index of type 'String'}}
270
318
// expected-note @-1 {{overloads for 'subscript' exist with these partially matching parameter lists: (String, Int), (String, String)}}
271
-
319
+
272
320
leta=s2["foo",1.0] // expected-error {{cannot subscript a value of type 'SubscriptTest2' with an index of type '(String, Double)'}}
273
321
// expected-note @-1 {{overloads for 'subscript' exist with these partially matching parameter lists: (String, Int), (String, String)}}
274
-
275
-
322
+
323
+
_ = s2.subscript("hello",6)
324
+
// expected-error@-1 {{value of type 'SubscriptTest2' has no property or method named 'subscript'; did you mean to use the subscript operator?}} {{9-10=}} {{10-19=}} {{19-20=[}} {{30-31=]}}
276
325
letb=s2[1,"foo"] // expected-error {{cannot convert value of type 'Int' to expected argument type 'String'}}
SR2575().subscript() // expected-error{{type 'SR2575' has no member 'subscript'}}
370
+
SR2575().subscript()
371
+
// expected-error@-1 {{value of type 'SR2575' has no property or method named 'subscript'; did you mean to use the subscript operator?}} {{9-10=}} {{10-19=}} {{19-20=[}} {{20-21=]}}
0 commit comments