// RUN: %target-typecheck-verify-swift // We used to accept this in Swift 6.0, but it's incorrect; // the primary associated types of a derived protocol might // be completely unrelated to those of a base protocol. protocol P : Q { associatedtype A } protocol Q { associatedtype B func getB() -> B } struct S: P { typealias A = T typealias B = Array var t: T func getB() -> Array { return [t] } } var p: any P = S(t: "hello world") var q: any Q = p // expected-error {{cannot convert value of type 'any P' to specified type 'any Q'}} // Previously we accepted the above conversion, and then getB() // would return something that was dynamically Array // and not String as expected. // print(q.getB()) // However, this is OK -- the two A's have the same name, so by the // semantics of the generics system they must be equivalent as type // parameters. protocol P1 { associatedtype A } protocol P2 { associatedtype A } protocol P3: P1, P2 { associatedtype A } func f(_ value: any P3) -> (any P1, any P2) { return (value, value) }