// RUN: %target-typecheck-verify-swift // RUN: not %target-swift-frontend -typecheck %s -debug-generic-signatures > %t.dump 2>&1 // RUN: %FileCheck %s < %t.dump class A { func foo() { } } class B : A { func bar() { } } class Other { } func f1(_: T) where T : Other {} // expected-error{{no type for 'T' can satisfy both 'T : Other' and 'T : A'}} // CHECK-LABEL: .f2@ // CHECK-NEXT: Generic signature: func f2(_: T) where T : B {} class GA {} class GB : GA {} protocol P {} func f3(_: T, _: U) where U : GA {} func f4(_: T, _: U) where U : GA {} func f5>(_: T, _: U) {} func f6, T : P>(_: T, _: U) {} func f7(_: T, _: U) where U : GA, T : P {} func f8>(_: T) where T : GA {} // expected-error{{no type for 'T' can satisfy both 'T : GA' and 'T : GA'}} // CHECK-LABEL: .f9@ // CHECK-NEXT: Generic signature: > func f9>(_: T) where T : GB {} // CHECK-LABEL: .f10@ // CHECK-NEXT: Generic signature: > func f10>(_: T) where T : GA {} func f11>(_: T) { } func f12, U : GB>(_: T, _: U) { } func f13>(_: T, _: U) { } // expected-error{{type 'T' constrained to non-protocol, non-class type 'U'}} // rdar://problem/24730536 // Superclass constraints can be used to resolve nested types to concrete types. protocol P3 { associatedtype T } protocol P2 { associatedtype T : P3 } class C : P3 { typealias T = Int } class S : P2 { typealias T = C } // CHECK-LABEL: .superclassConformance1(t:)@ // CHECK-NEXT: Generic signature: func superclassConformance1(t: T) where T : C, T : P3 {} // CHECK-LABEL: .superclassConformance2(t:)@ // CHECK-NEXT: Generic signature: func superclassConformance2(t: T) where T : C, T : P3 {} protocol P4 { } class C2 : C, P4 { } // CHECK-LABEL: .superclassConformance3(t:)@ // CHECK-NEXT: Generic signature: func superclassConformance3(t: T) where T : C, T : P4, T : C2 {} protocol P5: A { } protocol P6: A, Other { } // expected-error {{no type for 'Self' can satisfy both 'Self : Other' and 'Self : A'}} // expected-error@-1{{multiple inheritance from classes 'A' and 'Other'}} func takeA(_: A) { } func takeP5(_ t: T) { takeA(t) // okay } protocol P7 { // expected-error@-1{{no type for 'Self.Assoc' can satisfy both 'Self.Assoc : Other' and 'Self.Assoc : A'}} associatedtype Assoc: A, Other } // CHECK-LABEL: .superclassConformance4@ // CHECK-NEXT: Generic signature: func superclassConformance4(_: T, _: U) where T.T: C, U.T: C, T.T == U.T { } // Lookup of superclass associated types from inheritance clause protocol Elementary { associatedtype Element func get() -> Element } class Classical : Elementary { func get() -> Int { return 0 } } // CHECK-LABEL: .genericFunc@ // CHECK-NEXT: Generic signature: func genericFunc(_: T, _: U) where T.Element == U.Element {} // Lookup within superclass constraints. protocol P8 { associatedtype B } class C8 { struct A { } } // CHECK-LABEL: .superclassLookup1@ // CHECK-NEXT: Generic signature: func superclassLookup1(_: T) where T.A == T.B { } // CHECK-LABEL: .superclassLookup2@ // CHECK-NEXT: Generic signature: func superclassLookup2(_: T) where T.A == T.B, T: C8 { } // CHECK-LABEL: .superclassLookup3@ // CHECK-NEXT: Generic signature: func superclassLookup3(_: T) where T.A == T.B, T: C8, T: P8 { } // https://github.com/apple/swift/issues/47741 class C9 {} protocol P9 {} class C10 : C9, P9 { } protocol P10 { associatedtype A: C9 } // CHECK-LABEL: .testP10@ // CHECK-NEXT: Generic signature: func testP10(_: T) where T: P10, T.A: C10 { } // Nested types of generic class-constrained type parameters. protocol Tail { associatedtype E } protocol Rump : Tail { associatedtype E = Self } class Horse: Rump { } // CHECK-LABEL: .hasRedundantConformanceConstraint@ // CHECK-NEXT: Generic signature: > func hasRedundantConformanceConstraint, T>(_: X) where X : Rump {} // https://github.com/apple/swift/issues/48432 protocol X { associatedtype Y : A } // CHECK-LABEL: .noRedundancyWarning@ // CHECK: Generic signature: func noRedundancyWarning(_ wrapper: C) where C.Y == B {} // [qualified lookup] https://github.com/apple/swift/issues/44798 protocol Init { init(x: ()) } class Base { required init(y: ()) {} } class Derived : Base {} func g(_: T.Type) { _ = T(x: ()) _ = T(y: ()) } // Binding a class-constrained generic parameter to a subclass existential is // not sound. struct G {} // expected-note@-1 2 {{requirement specified as 'T' : 'Base' [with T = any Base & P]}} _ = G() // expected-error {{'G' requires that 'any Base & P' inherit from 'Base'}} func badClassConstrainedType(_: G) {} // expected-error@-1 {{'G' requires that 'any Base & P' inherit from 'Base'}} // Reduced from CoreStore in source compat suite public protocol Pony {} public class Teddy: Pony {} public struct Paddock {} public struct Barn { // CHECK-LABEL: Barn.foo@ // CHECK: Generic signature: public func foo(_: S, _: Barn, _: Paddock) {} } public class Animal { } @available(*, unavailable, message: "Not a pony") extension Animal: Pony { } public struct AnimalWrapper { } // CHECK-LABEL: ExtensionDecl line={{.*}} base=AnimalWrapper // FIXME: This should be // taking into account conformance availability. // CHECK-NEXT: Generic signature: extension AnimalWrapper: Pony where Friend: Pony { }