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
Opened existentials should be erased to the dependent upper bound
if the dependent member can be reduced to a concrete type. This
allows the generic signature to support parameterized protocol types
and bound generic class types by producing a more specific constraint
instead of just a plain protocol or class.
Copy file name to clipboardExpand all lines: test/Constraints/opened_existentials.swift
+14-8Lines changed: 14 additions & 8 deletions
Original file line number
Diff line number
Diff line change
@@ -256,7 +256,7 @@ func testExplicitCoercionRequirement(v: any B, otherV: any B & D) {
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
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}}
259
+
_ =getNoError(v)
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
@@ -306,7 +306,6 @@ func testExplicitCoercionRequirement(v: any B, otherV: any B & D) {
306
306
getP((v.getC()asanyP)) // Ok - parens avoid opening suppression
307
307
}
308
308
309
-
// Generic Class Types
310
309
classC1{}
311
310
classC2<T>:C1{}
312
311
@@ -318,8 +317,15 @@ protocol P1 {
318
317
func returnAssocTypeB()->B
319
318
}
320
319
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}}
320
+
func testAssocReturn(p:anyP1){
321
+
let _ = p.returnAssocTypeB() // returns C1
322
+
}
323
+
324
+
protocolQ2:P1where A ==Int{}
325
+
326
+
do{
327
+
letq:anyQ2
328
+
let _ = q.returnAssocTypeB() // returns C1
323
329
}
324
330
325
331
// Test Primary Associated Types
@@ -330,8 +336,8 @@ protocol P2<A> {
330
336
func returnAssocTypeB()->B
331
337
}
332
338
333
-
func testAssocReturn(p:anyP2<Int>){ // should return C2<A>
// Confirm there is no way to access Primary Associated Type
355
+
// Confirm there is no way to access Primary Associated Type directly
350
356
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}}
0 commit comments