1
+ // RUN: %target-typecheck-verify-swift -strict-concurrency=complete -disable-availability-checking -parse-as-library
1
2
// RUN: %target-run-simple-swift( -Xfrontend -disable-availability-checking -parse-as-library)
2
3
3
4
// REQUIRES: concurrency
@@ -15,7 +16,22 @@ struct SomeError: Error, Equatable {
15
16
var value = Int . random ( in: 0 ..< 100 )
16
17
}
17
18
18
- var tests = TestSuite ( " AsyncStream " )
19
+ class NotSendable { }
20
+
21
+ @MainActor func testWarnings( ) {
22
+ var x = 0
23
+ _ = AsyncStream {
24
+ x += 1 // expected-warning {{mutation of captured var 'x' in concurrently-executing code; this is an error in the Swift 6 language mode}}
25
+ return 0
26
+ }
27
+
28
+ _ = AsyncThrowingStream {
29
+ x += 1 // expected-warning {{mutation of captured var 'x' in concurrently-executing code; this is an error in the Swift 6 language mode}}
30
+ return
31
+ }
32
+ }
33
+
34
+ @MainActor var tests = TestSuite ( " AsyncStream " )
19
35
20
36
@main struct Main {
21
37
static func main( ) async {
@@ -29,7 +45,7 @@ var tests = TestSuite("AsyncStream")
29
45
continuation. yield ( " hello " )
30
46
31
47
var iterator = stream. makeAsyncIterator ( )
32
- expectEqual ( await iterator. next ( ) , " hello " )
48
+ expectEqual ( await iterator. next ( isolation : #isolation ) , " hello " )
33
49
}
34
50
35
51
tests. test ( " throwing factory method " ) {
@@ -38,7 +54,7 @@ var tests = TestSuite("AsyncStream")
38
54
39
55
var iterator = stream. makeAsyncIterator ( )
40
56
do {
41
- expectEqual ( try await iterator. next ( ) , " hello " )
57
+ expectEqual ( try await iterator. next ( isolation : #isolation ) , " hello " )
42
58
} catch {
43
59
expectUnreachable ( " unexpected error thrown " )
44
60
}
@@ -61,7 +77,7 @@ var tests = TestSuite("AsyncStream")
61
77
continuation. yield ( " hello " )
62
78
}
63
79
var iterator = series. makeAsyncIterator ( )
64
- expectEqual ( await iterator. next ( ) , " hello " )
80
+ expectEqual ( await iterator. next ( isolation : #isolation ) , " hello " )
65
81
}
66
82
67
83
tests. test ( " yield with awaiting next throwing " ) {
@@ -70,7 +86,7 @@ var tests = TestSuite("AsyncStream")
70
86
}
71
87
var iterator = series. makeAsyncIterator ( )
72
88
do {
73
- expectEqual ( try await iterator. next ( ) , " hello " )
89
+ expectEqual ( try await iterator. next ( isolation : #isolation ) , " hello " )
74
90
} catch {
75
91
expectUnreachable ( " unexpected error thrown " )
76
92
}
@@ -82,8 +98,8 @@ var tests = TestSuite("AsyncStream")
82
98
continuation. yield ( " world " )
83
99
}
84
100
var iterator = series. makeAsyncIterator ( )
85
- expectEqual ( await iterator. next ( ) , " hello " )
86
- expectEqual ( await iterator. next ( ) , " world " )
101
+ expectEqual ( await iterator. next ( isolation : #isolation ) , " hello " )
102
+ expectEqual ( await iterator. next ( isolation : #isolation ) , " world " )
87
103
}
88
104
89
105
tests. test ( " yield with awaiting next 2 throwing " ) {
@@ -93,8 +109,8 @@ var tests = TestSuite("AsyncStream")
93
109
}
94
110
var iterator = series. makeAsyncIterator ( )
95
111
do {
96
- expectEqual ( try await iterator. next ( ) , " hello " )
97
- expectEqual ( try await iterator. next ( ) , " world " )
112
+ expectEqual ( try await iterator. next ( isolation : #isolation ) , " hello " )
113
+ expectEqual ( try await iterator. next ( isolation : #isolation ) , " world " )
98
114
} catch {
99
115
expectUnreachable ( " unexpected error thrown " )
100
116
}
@@ -107,9 +123,9 @@ var tests = TestSuite("AsyncStream")
107
123
continuation. finish ( )
108
124
}
109
125
var iterator = series. makeAsyncIterator ( )
110
- expectEqual ( await iterator. next ( ) , " hello " )
111
- expectEqual ( await iterator. next ( ) , " world " )
112
- expectEqual ( await iterator. next ( ) , nil )
126
+ expectEqual ( await iterator. next ( isolation : #isolation ) , " hello " )
127
+ expectEqual ( await iterator. next ( isolation : #isolation ) , " world " )
128
+ expectEqual ( await iterator. next ( isolation : #isolation ) , nil )
113
129
}
114
130
115
131
tests. test ( " yield with awaiting next 2 and finish throwing " ) {
@@ -120,9 +136,9 @@ var tests = TestSuite("AsyncStream")
120
136
}
121
137
var iterator = series. makeAsyncIterator ( )
122
138
do {
123
- expectEqual ( try await iterator. next ( ) , " hello " )
124
- expectEqual ( try await iterator. next ( ) , " world " )
125
- expectEqual ( try await iterator. next ( ) , nil )
139
+ expectEqual ( try await iterator. next ( isolation : #isolation ) , " hello " )
140
+ expectEqual ( try await iterator. next ( isolation : #isolation ) , " world " )
141
+ expectEqual ( try await iterator. next ( isolation : #isolation ) , nil )
126
142
} catch {
127
143
expectUnreachable ( " unexpected error thrown " )
128
144
}
@@ -137,9 +153,9 @@ var tests = TestSuite("AsyncStream")
137
153
}
138
154
var iterator = series. makeAsyncIterator ( )
139
155
do {
140
- expectEqual ( try await iterator. next ( ) , " hello " )
141
- expectEqual ( try await iterator. next ( ) , " world " )
142
- _ = try await iterator. next ( )
156
+ expectEqual ( try await iterator. next ( isolation : #isolation ) , " hello " )
157
+ expectEqual ( try await iterator. next ( isolation : #isolation ) , " world " )
158
+ _ = try await iterator. next ( isolation : #isolation )
143
159
expectUnreachable ( " expected thrown error " )
144
160
} catch {
145
161
if let failure = error as? SomeError {
@@ -173,7 +189,7 @@ var tests = TestSuite("AsyncStream")
173
189
}
174
190
}
175
191
var iterator = series. makeAsyncIterator ( )
176
- expectEqual ( await iterator. next ( ) , " hello " )
192
+ expectEqual ( await iterator. next ( isolation : #isolation ) , " hello " )
177
193
}
178
194
179
195
tests. test ( " yield with awaiting next detached throwing " ) {
@@ -184,7 +200,7 @@ var tests = TestSuite("AsyncStream")
184
200
}
185
201
var iterator = series. makeAsyncIterator ( )
186
202
do {
187
- expectEqual ( try await iterator. next ( ) , " hello " )
203
+ expectEqual ( try await iterator. next ( isolation : #isolation ) , " hello " )
188
204
} catch {
189
205
expectUnreachable ( " unexpected error thrown " )
190
206
}
@@ -198,8 +214,8 @@ var tests = TestSuite("AsyncStream")
198
214
}
199
215
}
200
216
var iterator = series. makeAsyncIterator ( )
201
- expectEqual ( await iterator. next ( ) , " hello " )
202
- expectEqual ( await iterator. next ( ) , " world " )
217
+ expectEqual ( await iterator. next ( isolation : #isolation ) , " hello " )
218
+ expectEqual ( await iterator. next ( isolation : #isolation ) , " world " )
203
219
}
204
220
205
221
tests. test ( " yield with awaiting next 2 detached throwing " ) {
@@ -211,8 +227,8 @@ var tests = TestSuite("AsyncStream")
211
227
}
212
228
var iterator = series. makeAsyncIterator ( )
213
229
do {
214
- expectEqual ( try await iterator. next ( ) , " hello " )
215
- expectEqual ( try await iterator. next ( ) , " world " )
230
+ expectEqual ( try await iterator. next ( isolation : #isolation ) , " hello " )
231
+ expectEqual ( try await iterator. next ( isolation : #isolation ) , " world " )
216
232
} catch {
217
233
expectUnreachable ( " unexpected error thrown " )
218
234
}
@@ -227,9 +243,9 @@ var tests = TestSuite("AsyncStream")
227
243
}
228
244
}
229
245
var iterator = series. makeAsyncIterator ( )
230
- expectEqual ( await iterator. next ( ) , " hello " )
231
- expectEqual ( await iterator. next ( ) , " world " )
232
- expectEqual ( await iterator. next ( ) , nil )
246
+ expectEqual ( await iterator. next ( isolation : #isolation ) , " hello " )
247
+ expectEqual ( await iterator. next ( isolation : #isolation ) , " world " )
248
+ expectEqual ( await iterator. next ( isolation : #isolation ) , nil )
233
249
}
234
250
235
251
tests. test ( " yield with awaiting next 2 and finish detached throwing " ) {
@@ -242,9 +258,9 @@ var tests = TestSuite("AsyncStream")
242
258
}
243
259
var iterator = series. makeAsyncIterator ( )
244
260
do {
245
- expectEqual ( try await iterator. next ( ) , " hello " )
246
- expectEqual ( try await iterator. next ( ) , " world " )
247
- expectEqual ( try await iterator. next ( ) , nil )
261
+ expectEqual ( try await iterator. next ( isolation : #isolation ) , " hello " )
262
+ expectEqual ( try await iterator. next ( isolation : #isolation ) , " world " )
263
+ expectEqual ( try await iterator. next ( isolation : #isolation ) , nil )
248
264
} catch {
249
265
expectUnreachable ( " unexpected error thrown " )
250
266
}
@@ -261,9 +277,9 @@ var tests = TestSuite("AsyncStream")
261
277
}
262
278
var iterator = series. makeAsyncIterator ( )
263
279
do {
264
- expectEqual ( try await iterator. next ( ) , " hello " )
265
- expectEqual ( try await iterator. next ( ) , " world " )
266
- _ = try await iterator. next ( )
280
+ expectEqual ( try await iterator. next ( isolation : #isolation ) , " hello " )
281
+ expectEqual ( try await iterator. next ( isolation : #isolation ) , " world " )
282
+ _ = try await iterator. next ( isolation : #isolation )
267
283
expectUnreachable ( " expected thrown error " )
268
284
} catch {
269
285
if let failure = error as? SomeError {
@@ -284,10 +300,10 @@ var tests = TestSuite("AsyncStream")
284
300
}
285
301
}
286
302
var iterator = series. makeAsyncIterator ( )
287
- expectEqual ( await iterator. next ( ) , " hello " )
288
- expectEqual ( await iterator. next ( ) , " world " )
289
- expectEqual ( await iterator. next ( ) , nil )
290
- expectEqual ( await iterator. next ( ) , nil )
303
+ expectEqual ( await iterator. next ( isolation : #isolation ) , " hello " )
304
+ expectEqual ( await iterator. next ( isolation : #isolation ) , " world " )
305
+ expectEqual ( await iterator. next ( isolation : #isolation ) , nil )
306
+ expectEqual ( await iterator. next ( isolation : #isolation ) , nil )
291
307
}
292
308
293
309
tests. test ( " yield with awaiting next 2 and finish detached with value after finish throwing " ) {
@@ -301,10 +317,10 @@ var tests = TestSuite("AsyncStream")
301
317
}
302
318
var iterator = series. makeAsyncIterator ( )
303
319
do {
304
- expectEqual ( try await iterator. next ( ) , " hello " )
305
- expectEqual ( try await iterator. next ( ) , " world " )
306
- expectEqual ( try await iterator. next ( ) , nil )
307
- expectEqual ( try await iterator. next ( ) , nil )
320
+ expectEqual ( try await iterator. next ( isolation : #isolation ) , " hello " )
321
+ expectEqual ( try await iterator. next ( isolation : #isolation ) , " world " )
322
+ expectEqual ( try await iterator. next ( isolation : #isolation ) , nil )
323
+ expectEqual ( try await iterator. next ( isolation : #isolation ) , nil )
308
324
} catch {
309
325
expectUnreachable ( " unexpected error thrown " )
310
326
}
@@ -322,10 +338,10 @@ var tests = TestSuite("AsyncStream")
322
338
}
323
339
var iterator = series. makeAsyncIterator ( )
324
340
do {
325
- expectEqual ( try await iterator. next ( ) , " hello " )
326
- expectEqual ( try await iterator. next ( ) , " world " )
327
- expectEqual ( try await iterator. next ( ) , nil )
328
- expectEqual ( try await iterator. next ( ) , nil )
341
+ expectEqual ( try await iterator. next ( isolation : #isolation ) , " hello " )
342
+ expectEqual ( try await iterator. next ( isolation : #isolation ) , " world " )
343
+ expectEqual ( try await iterator. next ( isolation : #isolation ) , nil )
344
+ expectEqual ( try await iterator. next ( isolation : #isolation ) , nil )
329
345
} catch {
330
346
expectUnreachable ( " unexpected error thrown " )
331
347
}
@@ -341,10 +357,10 @@ var tests = TestSuite("AsyncStream")
341
357
}
342
358
var iterator = series. makeAsyncIterator ( )
343
359
do {
344
- expectEqual ( try await iterator. next ( ) , " hello " )
345
- expectEqual ( try await iterator. next ( ) , " world " )
346
- expectEqual ( try await iterator. next ( ) , nil )
347
- expectEqual ( try await iterator. next ( ) , nil )
360
+ expectEqual ( try await iterator. next ( isolation : #isolation ) , " hello " )
361
+ expectEqual ( try await iterator. next ( isolation : #isolation ) , " world " )
362
+ expectEqual ( try await iterator. next ( isolation : #isolation ) , nil )
363
+ expectEqual ( try await iterator. next ( isolation : #isolation ) , nil )
348
364
} catch {
349
365
expectUnreachable ( " unexpected error thrown " )
350
366
}
0 commit comments