Skip to content

Commit 4109315

Browse files
committed
Add a test for the rethrows behavior of async sequences and iterators
1 parent 239f8d8 commit 4109315

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// RUN: %target-swift-frontend -disable-availability-checking %s -emit-sil -o /dev/null -verify
2+
3+
// REQUIRES: concurrency
4+
5+
// Tests for the use of 'rethrows' on generic functions that have AsyncSequence
6+
// and AsyncIteratorProtocol requirements.
7+
8+
func f1(_ seq: some AsyncSequence) async rethrows {
9+
for try await _ in seq { }
10+
}
11+
12+
func f2(_ seq: some AsyncSequence, body: () throws -> Void) async rethrows {
13+
for try await _ in seq {
14+
try body()
15+
}
16+
}
17+
18+
func f3(_ seq: some AsyncSequence, _ seq2: some AsyncSequence) async rethrows {
19+
for try await _ in seq {
20+
}
21+
22+
for try await _ in seq2 {
23+
}
24+
}
25+
26+
enum HomeworkError: Error {
27+
case dogAteIt
28+
}
29+
30+
func testCalls(x: some AsyncSequence<Int, Never>, y: any AsyncSequence<Int, any Error>) async throws {
31+
await f1(x)
32+
try await f1(y)
33+
34+
await f2(x) { print("Hello") }
35+
try await f2(y) { print("Hello") }
36+
37+
try await f2(x) { throw HomeworkError.dogAteIt }
38+
try await f2(y) { throw HomeworkError.dogAteIt }
39+
40+
await f3(x, x)
41+
try await f3(x, y)
42+
}

0 commit comments

Comments
 (0)