|
1 | 1 | // RUN: %target-typecheck-verify-swift -disable-availability-checking
|
2 | 2 | // REQUIRES: concurrency
|
3 | 3 |
|
| 4 | +func testAsyncSequenceTypedPatternSendable<Seq: AsyncSequence>(_ seq: Seq) async throws where Seq.Element == Int, Seq: Sendable { |
| 5 | + async let result: Int = seq.reduce(0) { $0 + $1 } // OK |
| 6 | + // expected-warning@-1{{immutable value 'result' was never used; consider replacing with '_' or removing it}} |
| 7 | +} |
| 8 | + |
| 9 | +func testAsyncSequenceTypedPattern1Sendable<Seq: AsyncSequence>(_ seq: Seq) async throws where Seq.Element == Int, Seq: Sendable { |
| 10 | + async let _: Int = seq.reduce(0) { $0 + $1 } // OK |
| 11 | +} |
| 12 | + |
| 13 | +func testAsyncSequenceSendable<Seq: AsyncSequence>(_ seq: Seq) async throws where Seq.Element == Int, Seq: Sendable { |
| 14 | + async let result = seq.reduce(0) { $0 + $1 } // OK |
| 15 | + // expected-warning@-1{{initialization of immutable value 'result' was never used; consider replacing with assignment to '_' or removing it}} |
| 16 | +} |
| 17 | + |
| 18 | +func testAsyncSequence1Sendable<Seq: AsyncSequence>(_ seq: Seq) async throws where Seq.Element == Int, Seq: Sendable { |
| 19 | + async let _ = seq.reduce(0) { $0 + $1 } // OK |
| 20 | +} |
| 21 | + |
| 22 | +// TODO(diagnostics): Add a tailored wording for implicit autoclosure captures in sendable warnings, because |
| 23 | +// from user perspective there is no closure capture, so diagnostic can be confusing. |
4 | 24 | func testAsyncSequenceTypedPattern<Seq: AsyncSequence>(_ seq: Seq) async throws where Seq.Element == Int {
|
5 | 25 | async let result: Int = seq.reduce(0) { $0 + $1 } // OK
|
6 | 26 | // expected-warning@-1{{immutable value 'result' was never used; consider replacing with '_' or removing it}}
|
| 27 | + // expected-warning@-2{{capture of 'seq' with non-sendable type 'Seq' in a `@Sendable` closure}} |
7 | 28 | }
|
8 | 29 |
|
9 | 30 | func testAsyncSequenceTypedPattern1<Seq: AsyncSequence>(_ seq: Seq) async throws where Seq.Element == Int {
|
10 | 31 | async let _: Int = seq.reduce(0) { $0 + $1 } // OK
|
| 32 | + // expected-warning@-1{{capture of 'seq' with non-sendable type 'Seq' in a `@Sendable` closure}} |
11 | 33 | }
|
12 | 34 |
|
13 | 35 | func testAsyncSequence<Seq: AsyncSequence>(_ seq: Seq) async throws where Seq.Element == Int {
|
14 | 36 | async let result = seq.reduce(0) { $0 + $1 } // OK
|
15 | 37 | // expected-warning@-1{{initialization of immutable value 'result' was never used; consider replacing with assignment to '_' or removing it}}
|
| 38 | + // expected-warning@-2{{capture of 'seq' with non-sendable type 'Seq' in a `@Sendable` closure}} |
16 | 39 | }
|
17 | 40 |
|
18 | 41 | func testAsyncSequence1<Seq: AsyncSequence>(_ seq: Seq) async throws where Seq.Element == Int {
|
19 | 42 | async let _ = seq.reduce(0) { $0 + $1 } // OK
|
| 43 | + // expected-warning@-1{{capture of 'seq' with non-sendable type 'Seq' in a `@Sendable` closure}} |
20 | 44 | }
|
0 commit comments