// RUN: %target-typecheck-verify-swift -warn-redundant-requirements // ----- protocol Foo { associatedtype Bar : Foo } struct Ouroboros : Foo { typealias Bar = Ouroboros } // ----- protocol P { associatedtype A : P } struct X { } func f(_ z: T) { _ = X() } // ----- protocol PP2 { associatedtype A : P2 = Self } protocol P2 : PP2 { associatedtype A = Self } struct X2 { } struct Y2 : P2 { typealias A = Y2 } func f(_ z: T) { _ = X2() } // ----- protocol P3 { associatedtype A: P4 = Self } protocol P4 : P3 {} protocol DeclaredP : P3, // expected-warning{{redundant conformance constraint 'Self' : 'P3'}} P4 {} struct Y3 : DeclaredP { } struct X3 {} func f2(_ a: T) { _ = X3() } f2(Y3()) // ----- protocol Alpha { associatedtype Beta: Gamma } protocol Gamma { associatedtype Delta: Alpha } struct Epsilon // expected-warning{{redundant conformance constraint 'U' : 'Gamma'}} where T.Beta == U, U.Delta == T {} // ----- protocol AsExistentialA { var delegate : AsExistentialB? { get } } protocol AsExistentialB { func aMethod(_ object : AsExistentialA) } protocol AsExistentialAssocTypeA { var delegate : AsExistentialAssocTypeB? { get } // expected-error {{use of protocol 'AsExistentialAssocTypeB' as a type must be written 'any AsExistentialAssocTypeB'}} } protocol AsExistentialAssocTypeB { func aMethod(_ object : AsExistentialAssocTypeA) associatedtype Bar } protocol AsExistentialAssocTypeAgainA { var delegate : AsExistentialAssocTypeAgainB? { get } associatedtype Bar } protocol AsExistentialAssocTypeAgainB { func aMethod(_ object : AsExistentialAssocTypeAgainA) // expected-error {{use of protocol 'AsExistentialAssocTypeAgainA' as a type must be written 'any AsExistentialAssocTypeAgainA'}} } // https://github.com/apple/swift/issues/43164 protocol A { associatedtype B1: B associatedtype C1: C mutating func addObserver(_ observer: B1, forProperty: C1) } protocol C { } protocol B { associatedtype BA: A associatedtype BC: C func observeChangeOfProperty(_ property: BC, observable: BA) }