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/opened_existentials.swift
+51-2Lines changed: 51 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -255,8 +255,8 @@ func testExplicitCoercionRequirement(v: any B, otherV: any B & D) {
255
255
256
256
_ =getTuple(v) // expected-error {{inferred result type '(any B, any P)' requires explicit coercion due to loss of generic requirements}} {{18-18=as (any B, any P)}}
257
257
_ =getTuple(v)as(anyB,anyP) // Ok
258
-
259
-
_ =getNoError(v) // Ok because T.C.A == Double
258
+
// Ok because T.C.A == Double
259
+
_ =getNoError(v) // expected-error {{inferred result type '(any B).C.A' requires explicit coercion due to loss of generic requirements}}
260
260
261
261
_ =getComplex(v) // expected-error {{inferred result type '([(x: (a: any P, b: Int), y: Int)], [Int : any P])' requires explicit coercion due to loss of generic requirements}} {{20-20=as ([(x: (a: any P, b: Int), y: Int)], [Int : any P])}}
262
262
_ =getComplex(v)as([(x:(a:anyP, b:Int), y:Int)],[Int:anyP]) // Ok
@@ -305,3 +305,52 @@ func testExplicitCoercionRequirement(v: any B, otherV: any B & D) {
305
305
getP((getC(v)asanyP)) // Ok - parens avoid opening suppression
306
306
getP((v.getC()asanyP)) // Ok - parens avoid opening suppression
307
307
}
308
+
309
+
// Generic Class Types
310
+
classC1{}
311
+
classC2<T>:C1{}
312
+
313
+
// Test Associated Types
314
+
protocolP1{
315
+
associatedtypeA
316
+
associatedtypeB:C2<A>
317
+
318
+
func returnAssocTypeB()->B
319
+
}
320
+
321
+
func testAssocReturn(p:anyP1){ // should return C1
322
+
let _ = p.returnAssocTypeB() // expected-error {{inferred result type 'C1' requires explicit coercion due to loss of generic requirements}} {{29-29=as C1}}
323
+
}
324
+
325
+
// Test Primary Associated Types
326
+
protocolP2<A>{
327
+
associatedtypeA
328
+
associatedtypeB:C2<A>
329
+
330
+
func returnAssocTypeB()->B
331
+
}
332
+
333
+
func testAssocReturn(p:anyP2<Int>){ // should return C2<A>
// Confirm there is no way to access Primary Associated Type
350
+
func testPrimaryAssocReturn(p:anyP3<Int>){
351
+
let _ = p.returnPrimaryAssocTypeA() //expected-error {{inferred result type '(any P3<Int>).A' requires explicit coercion due to loss of generic requirements}}
352
+
}
353
+
354
+
func testPrimaryAssocCollection(p:anyP3<Float>){
355
+
let _:anyCollection<Float>= p.returnAssocTypeCollection()
)->anyClass<Struct<Bool>.Inner>&ConcreteAssocTypes= arg.method4 // expected-error {{inferred result type 'any Class<Struct<(any ConcreteAssocTypes).A7>.Inner> & ConcreteAssocTypes' requires explicit coercion due to loss of generic requirements}}
let _:anyClass<Struct<Bool>.Inner>&ConcreteAssocTypes=
804
-
arg[
805
+
arg[ // expected-error {{inferred result type 'any Class<Struct<(any ConcreteAssocTypes).A7>.Inner> & ConcreteAssocTypes' requires explicit coercion due to loss of generic requirements}}
let _:anyClass2Base&CovariantAssocTypeErasure= exist.method6()
920
921
let _:anyClass2Base&CovariantAssocTypeErasure= exist.method7()
921
-
922
922
let _:Any?= exist.method8()
923
923
let _:(AnyObject,Bool)= exist.method9()
924
924
let _:anyCovariantAssocTypeErasure.Type= exist.method10()
925
925
let _:Array<Class2Base>= exist.method11()
926
926
let _:Dictionary<String,Class2Base>= exist.method12()
927
+
928
+
let _ = exist.method1()
929
+
let _ = exist.method2()
930
+
let _ = exist.method3()
931
+
let _ = exist.method4()
932
+
let _ = exist.method5() // expected-error {{inferred result type 'Class2Base' requires explicit coercion due to loss of generic requirements}}{{24-24=as Class2Base}}
933
+
let _ = exist.method6()
934
+
let _ = exist.method7() // expected-error {{inferred result type 'any Class2Base & CovariantAssocTypeErasure' requires explicit coercion due to loss of generic requirements}}{{24-24=as any Class2Base & CovariantAssocTypeErasure}}
935
+
let _ = exist.method8()
936
+
let _ = exist.method9()
937
+
let _ = exist.method10()
938
+
let _ = exist.method11()
939
+
let _ = exist.method12() // expected-error {{inferred result type 'Dictionary<String, Class2Base>' requires explicit coercion due to loss of generic requirements}}{{25-25=as Dictionary<String, Class2Base>}}
0 commit comments