|
1 | 1 | // RUN: %target-typecheck-verify-swift -disable-availability-checking -warn-concurrency |
2 | 2 | // REQUIRES: concurrency |
3 | 3 |
|
4 | | -class NotConcurrent { } // expected-note 21{{class 'NotConcurrent' does not conform to the 'Sendable' protocol}} |
| 4 | +class NotConcurrent { } // expected-note 26{{class 'NotConcurrent' does not conform to the 'Sendable' protocol}} |
5 | 5 |
|
6 | 6 | // ---------------------------------------------------------------------- |
7 | 7 | // Sendable restriction on actor operations |
@@ -131,8 +131,9 @@ func testConcurrency() { |
131 | 131 | print(y) // okay |
132 | 132 | } |
133 | 133 | acceptConcurrent { |
134 | | - print(x) // expected-warning{{cannot use let 'x' with a non-sendable type 'NotConcurrent' from concurrently-executed code}} |
135 | | - print(y) // expected-error{{reference to captured var 'y' in concurrently-executing code}} |
| 134 | + print(x) // expected-warning{{capture of 'x' with non-sendable type 'NotConcurrent' in a `@Sendable` closure}} |
| 135 | + print(y) // expected-warning{{capture of 'y' with non-sendable type 'NotConcurrent' in a `@Sendable` closure}} |
| 136 | + // expected-error@-1{{reference to captured var 'y' in concurrently-executing code}} |
136 | 137 | } |
137 | 138 | } |
138 | 139 |
|
@@ -226,7 +227,7 @@ func acceptConcurrentUnary<T>(_: @Sendable (T) -> T) { } |
226 | 227 | func concurrentClosures<T>(_: T) { |
227 | 228 | acceptConcurrentUnary { (x: T) in |
228 | 229 | _ = x // ok |
229 | | - acceptConcurrentUnary { _ in x } // expected-warning{{cannot use parameter 'x' with a non-sendable type 'T' from concurrently-executed code}} |
| 230 | + acceptConcurrentUnary { _ in x } // expected-warning{{capture of 'x' with non-sendable type 'T' in a `@Sendable` closure}} |
230 | 231 | } |
231 | 232 | } |
232 | 233 |
|
@@ -286,6 +287,28 @@ final class C7<T>: Sendable { } |
286 | 287 |
|
287 | 288 | class C9: Sendable { } // expected-warning{{non-final class 'C9' cannot conform to 'Sendable'; use '@unchecked Sendable'}} |
288 | 289 |
|
| 290 | +extension NotConcurrent { |
| 291 | + func f() { } |
| 292 | + |
| 293 | + func test() { |
| 294 | + Task { |
| 295 | + f() // expected-warning{{capture of 'self' with non-sendable type 'NotConcurrent' in a `@Sendable` closure}} |
| 296 | + } |
| 297 | + |
| 298 | + Task { |
| 299 | + self.f() // expected-warning{{capture of 'self' with non-sendable type 'NotConcurrent' in a `@Sendable` closure}} |
| 300 | + } |
| 301 | + |
| 302 | + Task { [self] in |
| 303 | + f() // expected-warning{{capture of 'self' with non-sendable type 'NotConcurrent' in a `@Sendable` closure}} |
| 304 | + } |
| 305 | + |
| 306 | + Task { [self] in |
| 307 | + self.f() // expected-warning{{capture of 'self' with non-sendable type 'NotConcurrent' in a `@Sendable` closure}} |
| 308 | + } |
| 309 | + } |
| 310 | +} |
| 311 | + |
289 | 312 | // ---------------------------------------------------------------------- |
290 | 313 | // @unchecked Sendable disabling checking |
291 | 314 | // ---------------------------------------------------------------------- |
@@ -327,7 +350,7 @@ enum E12<T>: UnsafeSendable { // expected-warning{{'UnsafeSendable' is deprecate |
327 | 350 | func testSendableOptionalInference(nc: NotConcurrent) { |
328 | 351 | var fn: (@Sendable () -> Void)? = nil |
329 | 352 | fn = { |
330 | | - print(nc) // expected-warning{{cannot use parameter 'nc' with a non-sendable type 'NotConcurrent' from concurrently-executed code}} |
| 353 | + print(nc) // expected-warning{{capture of 'nc' with non-sendable type 'NotConcurrent' in a `@Sendable` closure}} |
331 | 354 | } |
332 | 355 | _ = fn |
333 | 356 | } |
0 commit comments