Skip to content

Commit dcd465e

Browse files
committed
[NoncopyableGenerics] additional test coverage
1 parent 2e66b69 commit dcd465e

File tree

4 files changed

+83
-13
lines changed

4 files changed

+83
-13
lines changed

test/Generics/inverse_protocols.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ struct File: ~Copyable, Eq {
2121
}
2222

2323
func check<T: ~Copyable>(_ a: T, _ b: borrowing T) -> Bool where T: Eq {
24-
// expected-error@-1 {{noncopyable parameter must specify its ownership}}
24+
// expected-error@-1 {{parameter of noncopyable type 'T' must specify ownership}}
2525
// expected-note@-2 {{add 'borrowing' for an immutable reference}}
2626
// expected-note@-3 {{add 'inout' for a mutable reference}}
2727
// expected-note@-4 {{add 'consuming' to take the value from the caller}}

test/Generics/inverse_protocols_errors.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ protocol NCProto: ~Copyable, RegularProto {
1010

1111
protocol Hello: ~Copyable {
1212
func greet(_ s: Self)
13-
// expected-error@-1 {{noncopyable parameter must specify its ownership}}
13+
// expected-error@-1 {{parameter of noncopyable type 'Self' must specify ownership}}
1414
// expected-note@-2 {{add 'borrowing' for an immutable reference}}
1515
// expected-note@-3 {{add 'inout' for a mutable reference}}
1616
// expected-note@-4 {{add 'consuming' to take the value from the caller}}
@@ -28,15 +28,15 @@ struct NCThinger<T: ~Copyable>: ~Copyable, Hello {
2828
deinit {}
2929

3030
func greet(_ f: Self) {}
31-
// expected-error@-1 {{noncopyable parameter must specify its ownership}}
31+
// expected-error@-1 {{parameter of noncopyable type 'NCThinger<T>' must specify ownership}}
3232
// expected-note@-2 {{add 'borrowing' for an immutable reference}}
3333
// expected-note@-3 {{add 'inout' for a mutable reference}}
3434
// expected-note@-4 {{add 'consuming' to take the value from the caller}}
3535

3636
func salute(_ s: borrowing Self) {}
3737

3838
func setThinger(_ t: T) {}
39-
// expected-error@-1 {{noncopyable parameter must specify its ownership}}
39+
// expected-error@-1 {{parameter of noncopyable type 'T' must specify ownership}}
4040
// expected-note@-2 {{add 'borrowing' for an immutable reference}}
4141
// expected-note@-3 {{add 'inout' for a mutable reference}}
4242
// expected-note@-4 {{add 'consuming' to take the value from the caller}}

test/Generics/inverse_signatures.swift

Lines changed: 70 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,42 @@ func genericFn<T>(_ t: T) {}
1010
// CHECK: Generic signature: <T>
1111
func withInverse<T: ~Copyable>(_ t: borrowing T) {}
1212

13+
// CHECK-LABEL: .where1@
14+
// CHECK: Generic signature: <T>
15+
func where1<T>(_ t: borrowing T) where T: ~Copyable {}
16+
17+
// CHECK-LABEL: .where2@
18+
// CHECK: Generic signature: <T where T : NoCopyP>
19+
func where2<T>(_ t: borrowing T) where T: NoCopyP, T: ~Copyable {}
20+
21+
// CHECK-LABEL: .where3@
22+
// CHECK: Generic signature: <T where T : CopyP>
23+
func where3<T>(_ t: T) where T: CopyP, T: ~Copyable {}
24+
25+
// CHECK-LABEL: .where4@
26+
// CHECK: Generic signature: <T where T : Equatable>
27+
func where4<T>(_ t: borrowing T) where T: Equatable, T: ~Copyable {}
28+
29+
// CHECK-LABEL: .compose1@
30+
// CHECK: Generic signature: <T where T : NoCopyP>
31+
func compose1<T: NoCopyP & ~Copyable>(_ t: borrowing T) {}
32+
33+
// CHECK-LABEL: .compose2@
34+
// CHECK: Generic signature: <T where T : CopyP>
35+
func compose2<T: CopyP & ~Copyable>(_ t: T) {}
36+
37+
// CHECK-LABEL: .compose3@
38+
// CHECK: Canonical generic signature: <τ_0_0 where τ_0_0 : CopyP>
39+
func compose3(_ t: some CopyP & ~Copyable) {}
40+
41+
// CHECK-LABEL: .compose4@
42+
// CHECK: Canonical generic signature: <τ_0_0 where τ_0_0 : NoCopyP>
43+
func compose4(_ t: inout some NoCopyP & ~Copyable) {}
44+
45+
// CHECK-LABEL: .f1@
46+
// CHECK: Generic signature: <T where T : Copyable, T : NoCopyP>
47+
func f1<T: NoCopyP>(_ t: T) {}
48+
1349
// CHECK-LABEL: .withSome@
1450
// CHECK: Canonical generic signature: <τ_0_0 where τ_0_0 : Copyable>
1551
func withSome(_ t: some Any) {}
@@ -24,7 +60,7 @@ func withSomeProto(_ t: some NoCopyP) {}
2460

2561
// CHECK-LABEL: .withInverseSome@
2662
// CHECK: Canonical generic signature: <τ_0_0>
27-
func withInverseSome(_ t: some ~Copyable) {}
63+
func withInverseSome(_ t: borrowing some ~Copyable) {}
2864

2965
// CHECK-LABEL: .S1@
3066
// CHECK: Generic signature: <T where T : Copyable>
@@ -44,7 +80,7 @@ class C1_IC<T: ~Copyable, U> {}
4480

4581
// CHECK-LABEL: .C1_CI@
4682
// CHECK: Generic signature: <T, U where T : Copyable>
47-
class C1_CI<T, U: ~Copyable> {}
83+
class C1_CI<T, U> where U: ~Copyable {}
4884

4985
// CHECK-LABEL: .C1_II@
5086
// CHECK: Generic signature: <T, U>
@@ -54,9 +90,25 @@ class C1_II<T: ~Copyable, U: ~Copyable> {}
5490
// CHECK: Requirement signature: <Self>
5591
protocol NoCopyP: ~Copyable {}
5692

57-
// CHECK-LABEL: .P1@
93+
// CHECK-LABEL: .NoCopyP2@
94+
// CHECK: Requirement signature: <Self where Self : NoCopyP>
95+
protocol NoCopyP2 where Self: ~Copyable & NoCopyP {}
96+
97+
// CHECK-LABEL: .CopyP@
5898
// CHECK: Requirement signature: <Self where Self : Copyable>
59-
protocol P1 {}
99+
protocol CopyP {}
100+
101+
// CHECK-LABEL: .CopyP2@
102+
// CHECK: Requirement signature: <Self where Self : CopyP>
103+
protocol CopyP2: CopyP, ~Copyable {} // expected-warning {{protocol 'CopyP2' should be declared to refine 'Copyable' due to a same-type constraint on 'Self'}}
104+
105+
// CHECK-LABEL: .CopyP2_Fixed@
106+
// CHECK: Requirement signature: <Self where Self : CopyP>
107+
protocol CopyP2_Fixed: CopyP {}
108+
109+
// CHECK-LABEL: .CopyInheritsNC@
110+
// CHECK: Requirement signature: <Self where Self : Copyable, Self : NoCopyP>
111+
protocol CopyInheritsNC: NoCopyP {}
60112

61113
// CHECK-LABEL: .P2@
62114
// CHECK: <Self where Self : Copyable, Self.[P2]A : Copyable>
@@ -73,3 +125,17 @@ protocol P2_CI { associatedtype A: ~Copyable }
73125
// CHECK-LABEL: .P2_II@
74126
// CHECK: Requirement signature: <Self>
75127
protocol P2_II: ~Copyable { associatedtype A: ~Copyable }
128+
129+
// CHECK-LABEL: .Cond@
130+
// CHECK: Generic signature: <T>
131+
// CHECK-NEXT: Canonical generic signature: <τ_0_0>
132+
struct Cond<T: ~Copyable>: ~Copyable {}
133+
134+
// CHECK-LABEL: ExtensionDecl line={{.*}} base=Cond
135+
// CHECK: Generic signature: <T where T : Copyable>
136+
// CHECK-NEXT: Canonical generic signature: <τ_0_0 where τ_0_0 : Copyable>
137+
138+
// CHECK-LABEL: ExtensionDecl line={{.*}} base=Cond
139+
// CHECK: (normal_conformance type="Cond<T>" protocol="Copyable"
140+
// CHECK-NEXT: (requirement "T" conforms_to "Copyable"))
141+
extension Cond: Copyable where T: Copyable {}

test/Parse/inverses.swift

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,13 @@ func more() {
1919

2020
struct S4: ~(Copyable & Equatable) {} // expected-error {{type 'Copyable & Equatable' is not invertible}}
2121

22-
func blah<T>(_ t: T) where T: ~Copyable,
23-
T: ~Hashable {} // expected-error@:31 {{type 'Hashable' is not invertible}}
22+
func blah<T>(_ t: borrowing T) where T: ~Copyable,
23+
T: ~Hashable {} // expected-error@:41 {{type 'Hashable' is not invertible}}
2424

2525
func foo<T: ~Copyable>(x: borrowing T) {}
2626

2727
struct Buurap<T: ~Copyable> {}
2828

29-
// expected-warning@+1 {{protocol 'Foo' should be declared to refine 'Copyable' due to a same-type constraint on 'Self'}}
3029
protocol Foo: ~Copyable // expected-note {{previous inverse constraint here}}
3130
where Self: ~Copyable { // expected-error {{duplicate inverse constraint}}
3231

@@ -53,16 +52,21 @@ extension S: ~Copyable {}
5352
struct S: ~U, // expected-error {{type 'U' is not invertible}}
5453
~Copyable {}
5554

56-
func greenBay<each T: ~Copyable>(_ r: repeat each T) {}
55+
func greenBay<each T: ~Copyable>(_ r: repeat each T) {} // expected-error{{cannot apply inverse '~Copyable' to type 'each T' in conformance requirement}}
5756

5857
typealias Clone = Copyable
5958
func dup<D: ~Clone>(_ d: D) {}
60-
// expected-error@-1 {{noncopyable parameter must specify its ownership}}
59+
// expected-error@-1 {{parameter of noncopyable type 'D' must specify ownership}}
6160
// expected-note@-2 {{add 'borrowing'}}
6261
// expected-note@-3 {{add 'inout'}}
6362
// expected-note@-4 {{add 'consuming'}}
6463

64+
// expected-error@+2 {{parameter of noncopyable type 'some ~Copyable' must specify ownership}}
65+
// expected-error@+1 {{parameter of noncopyable type 'some ~Clone' must specify ownership}}
6566
func superb(_ thing: some ~Copyable, thing2: some ~Clone) {}
67+
// expected-note@-1 2{{add 'borrowing'}}
68+
// expected-note@-2 2{{add 'inout'}}
69+
// expected-note@-3 2{{add 'consuming'}}
6670

6771
func ownership1(_ t: borrowing any ~Equatable) {} // expected-error {{type 'Equatable' is not invertible}}
6872

0 commit comments

Comments
 (0)