// RUN: %target-typecheck-verify-swift struct X { } // expected-note 4{{requirement specified as 'T' : 'AnyObject'}} class C { } struct S { } protocol P { } let okay0: X struct Y { let okay1: X } struct Y2 { let okay2: X } let bad0: X // expected-error{{'X' requires that 'any C & P' be a class type}} let bad1: X

// expected-error{{'X' requires that 'any P' be a class type}} let bad2: X // expected-error{{'X' requires that 'S' be a class type}} struct Z { let bad3: X // expected-error{{'X' requires that 'U' be a class type}} } // https://github.com/apple/swift/issues/49716 // Layout constraints weren't getting merged. protocol P1 { associatedtype A var a: A { get } } protocol P2 { associatedtype B: P1 var b: B { get } } func requiresAnyObject(_: T) { } func anyObjectConstraint(_ t: T, _ u: U) where T.B.A: AnyObject, U.B: AnyObject, T.B == T.B.A, U.B.A == U.B { requiresAnyObject(t.b) requiresAnyObject(u.b) requiresAnyObject(t.b.a) requiresAnyObject(u.b.a) } func test_class_constraint_diagnostics_with_contextual_type() { func foo(_: AnyObject) -> T {} // expected-note 2 {{where 'T' = 'any P'}} class A : P {} // TODO(diagnostics): We could also add a note here that protocols do not conform to themselves let _: P = foo(A() as AnyObject) // expected-error {{local function 'foo' requires that 'any P' be a class type}} let _: P = foo(A()) // expected-error {{local function 'foo' requires that 'any P' be a class type}} }