|
1 | 1 | // RUN: %target-typecheck-verify-swift
|
2 | 2 |
|
3 |
| -// Inheritable: method with 'Self' in its signature |
| 3 | +// Inheritable: method with 'Self' in contravariant position. |
4 | 4 | protocol P1 {
|
5 |
| - func f1(_ x: Self?) -> Bool |
| 5 | + func f1a(_ x: Self?) -> Bool |
| 6 | + |
| 7 | + func f1b(_ x: [Self]) |
| 8 | + |
| 9 | + func f1c(_ x: [String : Self]) |
6 | 10 | }
|
7 | 11 |
|
8 | 12 | // Inheritable: property with 'Self' in its signature.
|
@@ -52,12 +56,13 @@ protocol P9 {
|
52 | 56 | static func ==(x: Self, y: Self) -> Bool
|
53 | 57 | }
|
54 | 58 |
|
55 |
| -// Never inheritable: method with 'Self' in a non-contravariant position. |
| 59 | +// Never inheritable: method with 'Self' in invariant position. |
| 60 | +struct G<T> {} |
56 | 61 | protocol P10 {
|
57 |
| - func f10(_ arr: [Self]) |
| 62 | + func f10(_ arr: G<Self>) |
58 | 63 | }
|
59 | 64 | protocol P10a {
|
60 |
| - func f10a(_ arr: [Self]) |
| 65 | + func f10a(_ arr: G<Self>) |
61 | 66 | }
|
62 | 67 |
|
63 | 68 | // Never inheritable: method with 'Self' in curried position.
|
@@ -91,7 +96,11 @@ protocol P15 {
|
91 | 96 | // non-final class.
|
92 | 97 | class A : P1, P2, P3, P4, P5, P6, P7, P8, P9, P10 {
|
93 | 98 | // P1
|
94 |
| - func f1(_ x: A?) -> Bool { return true } |
| 99 | + func f1a(_ x: A?) -> Bool { return true } |
| 100 | + |
| 101 | + func f1b(_ x: [A]) { } |
| 102 | + |
| 103 | + func f1c(_ x: [String : A]) { } |
95 | 104 |
|
96 | 105 | // P2
|
97 | 106 | var prop2: A { // expected-error{{property 'prop2' in non-final class 'A' must specify type 'Self' to conform to protocol 'P2'}}
|
@@ -135,10 +144,10 @@ class A : P1, P2, P3, P4, P5, P6, P7, P8, P9, P10 {
|
135 | 144 | required init(int: Int) { }
|
136 | 145 |
|
137 | 146 | // P10
|
138 |
| - func f10(_ arr: [A]) { } // expected-error{{protocol 'P10' requirement 'f10' cannot be satisfied by a non-final class ('A') because it uses 'Self' in a non-parameter, non-result type position}} |
| 147 | + func f10(_ arr: G<A>) { } // expected-error{{protocol 'P10' requirement 'f10' cannot be satisfied by a non-final class ('A') because it uses 'Self' in a non-parameter, non-result type position}} |
139 | 148 |
|
140 | 149 | // P10a
|
141 |
| - func f10a(_ arr: [A]) { } // expected-note {{'f10a' declared here}} |
| 150 | + func f10a(_ arr: G<A>) { } // expected-note {{'f10a' declared here}} |
142 | 151 |
|
143 | 152 | // P11
|
144 | 153 | func f11() -> (_ x: A) -> Int { return { x in 5 } }
|
@@ -196,7 +205,11 @@ func testB8(_ b8: B8) {
|
196 | 205 | // Class A9 conforms to everything.
|
197 | 206 | final class A9 : P1, P2, P3, P4, P5, P6, P7, P8, P9, P10 {
|
198 | 207 | // P1
|
199 |
| - func f1(_ x: A9?) -> Bool { return true } |
| 208 | + func f1a(_ x: A9?) -> Bool { return true } |
| 209 | + |
| 210 | + func f1b(_ x: [A9]) { } |
| 211 | + |
| 212 | + func f1c(_ x: [String : A9]) { } |
200 | 213 |
|
201 | 214 | // P2
|
202 | 215 | var prop2: A9 {
|
@@ -231,7 +244,7 @@ final class A9 : P1, P2, P3, P4, P5, P6, P7, P8, P9, P10 {
|
231 | 244 | required init(int: Int) { }
|
232 | 245 |
|
233 | 246 | // P10
|
234 |
| - func f10(_ arr: [A9]) { } |
| 247 | + func f10(_ arr: G<A9>) { } |
235 | 248 |
|
236 | 249 | // P11
|
237 | 250 | func f11() -> (_ x: A9) -> Int { return { x in 5 } }
|
|
0 commit comments