// RUN: %target-typecheck-verify-swift protocol P { associatedtype A } struct S: P {} // expected-error@+1 {{same-type constraint 'Self' == 'S' is recursive}} extension P where Self == S { func f1(_: A) -> Self {} } // expected-error@+1 {{same-type constraint 'Self' == 'S' is recursive}} extension P where Self == S { func f2(_: A) -> Self {} } class C: P {} // expected-note@+3 {{while resolving type 'A'}} // expected-note@+2 {{while resolving type 'C'}} // expected-error@+1 {{extension of protocol 'P' has self-referential generic requirements}} extension P where Self : C { func f(_: A) -> Self {} } // expected-error@+1 {{superclass constraint 'Self' : 'C' is recursive}} extension P where Self : C { func f(_: A) -> Self {} } // https://github.com/apple/swift/issues/59476 protocol Fruit { associatedtype Output var output: Output? { get } } struct MapFruit: Fruit { var output: Output? { fatalError() } } struct Garden: Fruit { // expected-error@+1 {{same-type constraint 'F' == 'MapFruit' is recursive}} init(fruit1: G) where F == MapFruit { } // expected-error@+1 {{same-type constraint 'F' == 'MapFruit' is recursive}} init(fruit2: G) where F == MapFruit { } var output: F.Output? { fatalError() } } // rdar://problem/90062518 extension Slice { // expected-error@+1 {{same-type constraint 'Base' == 'UnsafeBufferPointer' is recursive}} public func withMemoryRebound( to type: T.Type, _ body: (UnsafeBufferPointer) throws -> Result ) rethrows -> Result where Base == UnsafeBufferPointer { let rebased = UnsafeBufferPointer(rebased: self) return try rebased.withMemoryRebound(to: T.self, body) } }