diff --git a/test/Generics/inverse_assoc_types.swift b/test/Generics/inverse_assoc_types.swift index d96b8e9fb5d..8ed117b33ba 100644 --- a/test/Generics/inverse_assoc_types.swift +++ b/test/Generics/inverse_assoc_types.swift @@ -50,3 +50,115 @@ protocol Iterable: ~Copyable { associatedtype Element: ~Copyable } + +struct ReqC {} + +func reqC(_ t: T) {} // expected-note 8{{'where T: Copyable' is implicit here}} + + +protocol ProvideA: ~Copyable { + associatedtype A: ~Copyable, ProvideB +} + +protocol ProvideB: ~Copyable { + associatedtype B: ~Copyable, ProvideA +} + +// via bound-parameter requirement inference, all of these associated types become copyable +func inferenceRec(_ t: T, + _ a1: ReqC, + _ b2: ReqC, + _ a3: ReqC, + _ b4: ReqC, + _ a5: ReqC, + _ b6: ReqC, + _ a7: ReqC, + _ b8: ReqC, + _ a9: ReqC, + _ b10: ReqC, + _ a11: ReqC, + _ b12: ReqC + ) {} + +// Otherwise, the archetypes infer Copyable based on the defaulting rule, +// no matter the depth. +func inferenceRec(_ t: T, + _ a1: borrowing T.A, + _ b2: borrowing T.A.B, + _ a3: borrowing T.A.B.A, + _ b4: borrowing T.A.B.A.B, + _ a5: borrowing T.A.B.A.B.A, + _ b6: borrowing T.A.B.A.B.A.B, + _ a7: borrowing T.A.B.A.B.A.B.A, + _ b8: borrowing T.A.B.A.B.A.B.A.B, + _ a9: borrowing T.A.B.A.B.A.B.A.B.A, + _ b10: borrowing T.A.B.A.B.A.B.A.B.A.B, + _ a11: borrowing T.A.B.A.B.A.B.A.B.A.B.A, + _ b12: borrowing T.A.B.A.B.A.B.A.B.A.B.A.B + ) { + reqC(a1) + reqC(b2) // expected-error {{requires that 'T.A.B' conform to 'Copyable'}} + reqC(a3) + reqC(b4) // expected-error {{requires that 'T.A.B.A.B' conform to 'Copyable'}} + reqC(a5) + reqC(b6) // expected-error {{requires that 'T.A.B.A.B.A.B' conform to 'Copyable'}} + reqC(a7) + reqC(b8) // expected-error {{requires that 'T.A.B.A.B.A.B.A.B' conform to 'Copyable'}} + reqC(a9) + reqC(b10) // expected-error {{requires that 'T.A.B.A.B.A.B.A.B.A.B' conform to 'Copyable'}} + reqC(a11) + reqC(b12) // expected-error {{requires that 'T.A.B.A.B.A.B.A.B.A.B.A.B' conform to 'Copyable'}} +} + +protocol Gen: ~Copyable { + associatedtype E: ~Copyable, Gen + associatedtype I: ~Copyable, Gen + + func e() -> E + func i() -> I +} + +func checkExistential(_ s: any Gen) { + reqC(s.e()) + reqC(s.e().e()) + reqC(s.e().e().e()) + reqC(s.e().e().e().e().e().e().e().e().e().e().e().e().e().e().e().e().e().e().e().e().e().e().e().e().e().e().e().e().e().e().e().e().e().e().e().e().e().e().e().e().e().e().e().e().e().e().e().e().e().e().e().e().e().e().e().e().e().e().e().e().e().e().e()) + + reqC(s.i()) // expected-error {{requires that 'T' conform to 'Copyable'}} + reqC(s.i().e()) + reqC(s.i().e().i()) // expected-error {{requires that 'T' conform to 'Copyable'}} + reqC(s.i().e().i().e()) +} + +protocol Veggie { + associatedtype A: ~Copyable + associatedtype NeedsCopyable +} +protocol Carrot: Veggie + where Self.NeedsCopyable: ~Copyable {} // expected-error {{'Self.NeedsCopyable' required to be 'Copyable' but is marked with '~Copyable'}} + // expected-error @-1{{cannot suppress '~Copyable' on generic parameter 'Self.NeedsCopyable' defined in outer scope}} + +protocol CarrotCake: Carrot where Self.A: ~Copyable {} // expected-error {{'Self.A' required to be 'Copyable' but is marked with '~Copyable'}} +// expected-error @-1{{cannot suppress '~Copyable' on generic parameter 'Self.A' defined in outer scope}} + + +protocol Bird { + associatedtype Song +} + +protocol Eagle: Bird where Self.Song: ~Copyable {}// expected-error {{'Self.Song' required to be 'Copyable' but is marked with '~Copyable'}} +// expected-error @-1{{cannot suppress '~Copyable' on generic parameter 'Self.Song' defined in outer scope}} + + +protocol Pushable { + associatedtype Element: ~Copyable +} + +struct Stack {} + +func push(_ s: Stack, _ v: Val) + where Val.Element: ~Copyable {} // expected-error {{'Val.Element' required to be 'Copyable' but is marked with '~Copyable'}} + +protocol Stackable: Pushable {} + +extension Stackable where Element: ~Copyable {} // expected-error {{'Self.Element' required to be 'Copyable' but is marked with '~Copyable'}} diff --git a/test/Generics/inverse_signatures_assoc_types.swift b/test/Generics/inverse_signatures_assoc_types.swift index 075f2e8c134..e47fb698565 100644 --- a/test/Generics/inverse_signatures_assoc_types.swift +++ b/test/Generics/inverse_signatures_assoc_types.swift @@ -79,6 +79,16 @@ extension Pri_IIII {} func test2(_ x: X, y: Y, z: Z) where X: Pri_CI, Y: Pri_II, Z: Pri_IIII {} +struct RequireCopy {} + +// CHECK-LABEL: .ImplyP@ +// CHECK-NEXT: Generic signature: +struct ImplyP where V: Pri_CI {} + +// CHECK-LABEL: .implied1@ +// CHECK-NEXT: Generic signature: +func implied1(_ t: ImplyP) {} + // CHECK-LABEL: .P3@ // CHECK: Requirement signature: protocol P3 where Self: (~Copyable & ~Escapable) { associatedtype B: ~Escapable } @@ -181,6 +191,28 @@ protocol Derived3: Base where Elm: ~Copyable {} // CHECK-NEXT: Requirement signature: protocol Derived4: Base, ~Copyable where Elm: ~Copyable {} +// CHECK-LABEL: .Derived5@ +// CHECK-NEXT: Requirement signature: +protocol Derived5: Base {} + +// CHECK-LABEL: .Derived6@ +// CHECK-NEXT: Requirement signature: +protocol Derived6: Base {} + +// CHECK-LABEL: .SecondOrder@ +// CHECK-NEXT: Requirement signature: +protocol SecondOrder: Derived6 {} + +// CHECK-LABEL: .SecondOrderSupp1@ +// CHECK-NEXT: Requirement signature: +protocol SecondOrderSupp1: Derived6 where Self.Iter: ~Copyable {} + +// CHECK-LABEL: .Derived7@ +// CHECK-NEXT: Requirement signature: +protocol Derived7: Base { + associatedtype Iter +} + // CHECK-LABEL: .SameType@ // CHECK-NEXT: Requirement signature: (_ t: T, _ a: T.A, _ aa: T.A.A, _ aaa: T.A.A.A) func testExpansion2(_ t: borrowing T) where T: ~Copyable & Ping, T.A: ~Copyable & Ping, T.A.A: ~Copyable & Ping, T.B: Ping, T.B.B: Ping {} + + +// CHECK-LABEL: .Iterable@ +// CHECK-NEXT: Requirement signature: +protocol Iterable: ~Copyable { + associatedtype Element: ~Copyable +} + +// CHECK-LABEL: .PersistedDictionary@ +// CHECK-NEXT: Requirement signature: +protocol PersistedDictionary: ~Copyable, Iterable { + associatedtype Key: ~Copyable + associatedtype Value: ~Copyable + associatedtype Strategy: ~Copyable +} + +// CHECK-LABEL: ExtensionDecl line={{.*}} base=PersistedDictionary +// CHECK-NEXT: Generic signature: +extension PersistedDictionary {}