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
Better generic fix-its for types as well as construction and casts.
Slava pointed out that we have an existing version of the code from
the previous commit that's only used when checking types. Replace it
with the new code, which handles more cases.
structFullyGeneric<Foo>{} // expected-note 2 {{'Foo' declared as parameter to type 'FullyGeneric'}}
263
+
structFullyGeneric<Foo>{} // expected-note 3 {{'Foo' declared as parameter to type 'FullyGeneric'}} expected-note 6 {{generic type 'FullyGeneric' declared here}}
264
264
265
-
structAnyClassBound<Foo:AnyObject>{} // expected-note {{'Foo' declared as parameter to type 'AnyClassBound'}}
265
+
structAnyClassBound<Foo:AnyObject>{} // expected-note {{'Foo' declared as parameter to type 'AnyClassBound'}} expected-note {{generic type 'AnyClassBound' declared here}}
266
266
structAnyClassBound2<Foo>where Foo:AnyObject{} // expected-note {{'Foo' declared as parameter to type 'AnyClassBound2'}}
267
267
268
-
structProtoBound<Foo:SubProto>{} // expected-note {{'Foo' declared as parameter to type 'ProtoBound'}}
268
+
structProtoBound<Foo:SubProto>{} // expected-note {{'Foo' declared as parameter to type 'ProtoBound'}} expected-note {{generic type 'ProtoBound' declared here}}
269
269
structProtoBound2<Foo>where Foo:SubProto{} // expected-note {{'Foo' declared as parameter to type 'ProtoBound2'}}
270
270
271
-
structObjCProtoBound<Foo:NSCopyish>{} // expected-note {{'Foo' declared as parameter to type 'ObjCProtoBound'}}
271
+
structObjCProtoBound<Foo:NSCopyish>{} // expected-note {{'Foo' declared as parameter to type 'ObjCProtoBound'}} expected-note {{generic type 'ObjCProtoBound' declared here}}
272
272
structObjCProtoBound2<Foo>where Foo:NSCopyish{} // expected-note {{'Foo' declared as parameter to type 'ObjCProtoBound2'}}
273
273
274
274
structClassBound<Foo:X>{} // expected-note {{generic type 'ClassBound' declared here}}
275
275
structClassBound2<Foo>where Foo:X{} // expected-note {{generic type 'ClassBound2' declared here}}
276
276
277
-
structProtosBound<Foo>where Foo:SubProto&NSCopyish{} // expected-note {{'Foo' declared as parameter to type 'ProtosBound'}}
277
+
structProtosBound<Foo>where Foo:SubProto&NSCopyish{} // expected-note {{'Foo' declared as parameter to type 'ProtosBound'}} expected-note {{generic type 'ProtosBound' declared here}}
278
278
structProtosBound2<Foo:SubProto&NSCopyish>{} // expected-note {{'Foo' declared as parameter to type 'ProtosBound2'}}
279
279
structProtosBound3<Foo:SubProto>where Foo:NSCopyish{} // expected-note {{'Foo' declared as parameter to type 'ProtosBound3'}}
let _:Int=Pair().first // expected-error {{generic parameter 'T' could not be inferred}} expected-note {{explicitly specify the generic arguments to fix this issue}} {{20-20=<Any, Any>}}
361
361
let _:Int=Pair().second // expected-error {{generic parameter 'T' could not be inferred}} expected-note {{explicitly specify the generic arguments to fix this issue}} {{20-20=<Any, Any>}}
362
362
}
363
+
364
+
func testFixItTypePosition(){
365
+
let _:FullyGeneric // expected-error {{reference to generic type 'FullyGeneric' requires arguments in <...>}} {{22-22=<Any>}}
366
+
let _:ProtoBound // expected-error {{reference to generic type 'ProtoBound' requires arguments in <...>}} {{20-20=<<#Foo: SubProto#>>}}
367
+
let _:ObjCProtoBound // expected-error {{reference to generic type 'ObjCProtoBound' requires arguments in <...>}} {{24-24=<NSCopyish>}}
368
+
let _:AnyClassBound // expected-error {{reference to generic type 'AnyClassBound' requires arguments in <...>}} {{23-23=<AnyObject>}}
369
+
let _:ProtosBound // expected-error {{reference to generic type 'ProtosBound' requires arguments in <...>}} {{21-21=<<#Foo: NSCopyish & SubProto#>>}}
370
+
}
371
+
372
+
func testFixItNested(){
373
+
_ =Array<FullyGeneric>() // expected-error {{reference to generic type 'FullyGeneric' requires arguments in <...>}} {{25-25=<Any>}}
374
+
_ =[FullyGeneric]() // expected-error {{generic parameter 'Foo' could not be inferred}} expected-note {{explicitly specify the generic arguments to fix this issue}} {{20-20=<Any>}}
375
+
376
+
_ =FullyGeneric<FullyGeneric>() // expected-error {{reference to generic type 'FullyGeneric' requires arguments in <...>}} {{32-32=<Any>}}
377
+
378
+
_ =Pair<
379
+
FullyGeneric, // expected-error {{reference to generic type 'FullyGeneric' requires arguments in <...>}} {{17-17=<Any>}}
380
+
FullyGeneric // FIXME: We could diagnose both of these, but we don't.
381
+
>()
382
+
_ =Pair<
383
+
FullyGeneric<Any>,
384
+
FullyGeneric // expected-error {{reference to generic type 'FullyGeneric' requires arguments in <...>}} {{17-17=<Any>}}
385
+
>()
386
+
_ =Pair<
387
+
FullyGeneric, // expected-error {{reference to generic type 'FullyGeneric' requires arguments in <...>}} {{17-17=<Any>}}
388
+
FullyGeneric<Any>
389
+
>()
390
+
391
+
// FIXME: These errors could be improved.
392
+
_ =pair( // expected-error {{generic parameter 'T' could not be inferred}} {{none}}
393
+
FullyGeneric(),
394
+
FullyGeneric()
395
+
)
396
+
_ =pair( // expected-error {{generic parameter 'T' could not be inferred}} {{none}}
397
+
FullyGeneric<Any>(),
398
+
FullyGeneric()
399
+
)
400
+
_ =pair( // expected-error {{generic parameter 'T' could not be inferred}} {{none}}
0 commit comments