Skip to content

Commit 5814b43

Browse files
[SR-15049] Add sendable test cases and todo for improving diagnostic wording
1 parent 9a10088 commit 5814b43

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

test/Concurrency/sr15049.swift

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,44 @@
11
// RUN: %target-typecheck-verify-swift -disable-availability-checking
22
// REQUIRES: concurrency
33

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.
424
func testAsyncSequenceTypedPattern<Seq: AsyncSequence>(_ seq: Seq) async throws where Seq.Element == Int {
525
async let result: Int = seq.reduce(0) { $0 + $1 } // OK
626
// 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}}
728
}
829

930
func testAsyncSequenceTypedPattern1<Seq: AsyncSequence>(_ seq: Seq) async throws where Seq.Element == Int {
1031
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}}
1133
}
1234

1335
func testAsyncSequence<Seq: AsyncSequence>(_ seq: Seq) async throws where Seq.Element == Int {
1436
async let result = seq.reduce(0) { $0 + $1 } // OK
1537
// 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}}
1639
}
1740

1841
func testAsyncSequence1<Seq: AsyncSequence>(_ seq: Seq) async throws where Seq.Element == Int {
1942
async let _ = seq.reduce(0) { $0 + $1 } // OK
43+
// expected-warning@-1{{capture of 'seq' with non-sendable type 'Seq' in a `@Sendable` closure}}
2044
}

0 commit comments

Comments
 (0)