// RUN: %target-typecheck-verify-swift -requirement-machine-inferred-signatures=verify protocol SomeProtocol { associatedtype T } extension SomeProtocol where T == Optional { } // expected-error{{same-type constraint 'Self.T' == 'Optional' is recursive}} // expected-error@-1 {{cannot build rewrite system for generic signature; concrete nesting limit exceeded}} // expected-note@-2 {{failed rewrite rule is τ_0_0.[SomeProtocol:T].[concrete: Optional>>>>>>>>>>>>>>>>>>>>>>>>>>>>>] => τ_0_0.[SomeProtocol:T]}} // rdar://problem/19840527 class X where T == X { // expected-error{{same-type constraint 'T' == 'X' is recursive}} // expected-error@-1 {{cannot build rewrite system for generic signature; concrete nesting limit exceeded}} // expected-note@-2 {{failed rewrite rule is τ_0_0.[concrete: X>>>>>>>>>>>>>>>>>>>>>>>>>>>>>] => τ_0_0}} // expected-error@-3{{same-type requirement makes generic parameter 'T' non-generic}} // expected-error@-4 6{{generic class 'X' has self-referential generic requirements}} var type: T { return Swift.type(of: self) } // expected-error{{cannot convert return expression of type 'X.Type' to return type 'T'}} } // FIXME: The "associated type 'Foo' is not a member type of 'Self'" diagnostic // should also become "associated type 'Foo' references itself" protocol CircularAssocTypeDefault { associatedtype Z = Z // expected-error{{associated type 'Z' references itself}} // expected-note@-1{{type declared here}} // expected-note@-2{{protocol requires nested type 'Z'; do you want to add it?}} associatedtype Z2 = Z3 // expected-note@-1{{protocol requires nested type 'Z2'; do you want to add it?}} associatedtype Z3 = Z2 // expected-note@-1{{protocol requires nested type 'Z3'; do you want to add it?}} associatedtype Z4 = Self.Z4 // expected-error{{associated type 'Z4' references itself}} // expected-note@-1{{type declared here}} // expected-note@-2{{protocol requires nested type 'Z4'; do you want to add it?}} associatedtype Z5 = Self.Z6 // expected-note@-1{{protocol requires nested type 'Z5'; do you want to add it?}} associatedtype Z6 = Self.Z5 // expected-note@-1{{protocol requires nested type 'Z6'; do you want to add it?}} } struct ConformsToCircularAssocTypeDefault : CircularAssocTypeDefault { } // expected-error@-1 {{type 'ConformsToCircularAssocTypeDefault' does not conform to protocol 'CircularAssocTypeDefault'}} // rdar://problem/20000145 public protocol P { associatedtype T } public struct S where A.T == S { // expected-error@-1 6{{generic struct 'S' has self-referential generic requirements}} func f(a: A.T) { g(a: id(t: a)) // `a` has error type which is diagnosed as circular reference _ = A.T.self } func g(a: S) { f(a: id(t: a)) _ = S.self } func id(t: T) -> T { return t } } protocol I { init() } protocol PI { associatedtype T : I } struct SI : I where A : I, A.T == SI { // expected-error@-1 6{{generic struct 'SI' has self-referential generic requirements}} func ggg(t: T.Type) -> T { return T() } func foo() { _ = A() _ = A.T() _ = SI() _ = ggg(t: A.self) _ = ggg(t: A.T.self) _ = self.ggg(t: A.self) _ = self.ggg(t: A.T.self) } } // Used to hit infinite recursion struct S4 : I where A : I { } struct S5 : I where A : I, A.T == S4 { } // Used to hit ArchetypeBuilder assertions struct SU where A.T == SU { // expected-error@-1 6{{generic struct 'SU' has self-referential generic requirements}} } struct SIU : I where A : I, A.T == SIU { // expected-error@-1 6{{generic struct 'SIU' has self-referential generic requirements}} }