File: do_expr.swift

package info (click to toggle)
swiftlang 6.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,519,992 kB
  • sloc: cpp: 9,107,863; ansic: 2,040,022; asm: 1,135,751; python: 296,500; objc: 82,456; f90: 60,502; lisp: 34,951; pascal: 19,946; sh: 18,133; perl: 7,482; ml: 4,937; javascript: 4,117; makefile: 3,840; awk: 3,535; xml: 914; fortran: 619; cs: 573; ruby: 573
file content (694 lines) | stat: -rw-r--r-- 21,569 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
// RUN: %target-typecheck-verify-swift -disable-availability-checking -enable-experimental-feature ThenStatements -enable-experimental-feature DoExpressions

// Required for experimental features
// REQUIRES: asserts

@discardableResult
func throwsError() throws -> Int { 0 }

struct Err: Error {}

func test1() -> Int {
  return do { 5 }
}

func test2() -> Int {
  return do { try throwsError() } catch { 0 }
}

func test3() -> Int {
  return
  do { 5 }
  // expected-warning@-1 {{expression following 'return' is treated as an argument of the 'return'}}
  // expected-note@-2 {{indent the expression to silence this warning}}
}

func test4() -> Int {
  return
    do { 5 }
}

func test5() -> Int {
  return
  do { try throwsError() } catch { 0 }
  // expected-warning@-1 {{expression following 'return' is treated as an argument of the 'return'}}
  // expected-note@-2 {{indent the expression to silence this warning}}
}

func test6() -> Int {
  return
    do { try throwsError() } catch { 0 }
}

func test7() -> Int {
  do { 5 }
}

func test8() -> Int {
  do { try throwsError() } catch { 0 }
}

func test9() -> Int {
  do { 5 } as Int
}

func test10() -> Int {
  do { try throwsError() } catch { 0 } as Int
}

func test11() -> Int {
  let x = do { 5 }
  return x
}

func test12() -> Int {
  let x = do { try throwsError() } catch { 0 }
  return x
}

func test13() -> Int {
  let fn = { do { 5 } }
  return fn()
}

func test14() -> Int {
  let fn = { do { try throwsError() } catch { 0 } }
  return fn()
}

func test15() -> Int {
  let x = if .random() {
    do { 0 }
  } else {
    1
  }
  return x
}

func test16() -> Int {
  let x = if .random() {
    1
  } else {
    do { 2 } catch { 3 }
    // expected-warning@-1 {{'catch' block is unreachable because no errors are thrown in 'do' block}}
  }
  return x
}

func test17() -> Int {
  if .random() {
    do { 0 }
  } else {
    1
  }
}

func test18() -> Int {
  if .random() {
    1
  } else {
    do { 2 } catch { 3 }
    // expected-warning@-1 {{'catch' block is unreachable because no errors are thrown in 'do' block}}
  }
}

func testEmpty1() {
  let _ = do {} // expected-error {{expected expression in branch of 'do' expression}}
}

func testEmpty2() -> Int {
  // Fine, treated as a statement.
  do {}
}

func testEmpty3() -> Int {
  let _ = do { try throwsError() } catch {}
  // expected-error@-1 {{expected expression in branch of 'do-catch' expression}}
}

func testEmpty4() -> Int {
  // Fine, treated as a statement.
  do { try throwsError() } catch {}
}

func testNonExhaustive1() throws -> Int {
  let _ = do { try throwsError() } catch is Err { 0 }
  // expected-error@-1 {{'do catch' must have an unconditional 'catch' to be used as expression}}
}

func testNonExhaustive2() throws -> Int {
  // Non-exhaustive, so statement.
  do { try throwsError() } catch is Err { 0 }
  // expected-warning@-1 {{integer literal is unused}}
}

func testReturn1() -> Int {
  let _ = do {
    try throwsError()
  } catch {
    if .random() {
      return 0 // expected-error {{cannot 'return' in 'do-catch' when used as expression}}
    }
    then 0
  }
}

func testReturn2() -> Int {
  // The return means this must be a statement.
  do {
    try throwsError()
  } catch {
    if .random() {
      return 0
    }
    then 0 // expected-error {{'then' may only appear as the last statement in an 'if', 'switch', or 'do' expression}}
  }
}

// MARK: Effect specifiers

func tryDo1() -> Int {
  try do { 0 }
  // expected-warning@-1 {{'try' has no effect on 'do' expression}}
}

func tryDo2() -> Int {
  let x = try do { 0 }
  // expected-warning@-1 {{'try' has no effect on 'do' expression}}
  return x
}

func tryDo3() -> Int {
  return try do { 0 }
  // expected-warning@-1 {{'try' has no effect on 'do' expression}}
}

func tryDo4() throws -> Int {
  return try do { 0 }
  // expected-warning@-1 {{'try' has no effect on 'do' expression}}
}

func tryDo5() throws -> Int {
  return try do { tryDo4() }
  // expected-warning@-1 {{'try' has no effect on 'do' expression}}
  // expected-warning@-2 {{call can throw but is not marked with 'try'; this is an error in the Swift 6 language mode}}
  // expected-note@-3 {{did you mean to use 'try'?}}
  // expected-note@-4 {{did you mean to handle error as optional value?}}
  // expected-note@-5 {{did you mean to disable error propagation?}}
}

func tryDo6() throws -> Int {
  try do { tryDo4() }
  // expected-warning@-1 {{'try' has no effect on 'do' expression}}
  // expected-warning@-2 {{call can throw but is not marked with 'try'; this is an error in the Swift 6 language mode}}
  // expected-note@-3 {{did you mean to use 'try'?}}
  // expected-note@-4 {{did you mean to handle error as optional value?}}
  // expected-note@-5 {{did you mean to disable error propagation?}}
}

func tryDo7() throws -> Int {
  let x = try do { tryDo4() }
  // expected-warning@-1 {{'try' has no effect on 'do' expression}}
  // expected-warning@-2 {{call can throw but is not marked with 'try'; this is an error in the Swift 6 language mode}}
  // expected-note@-3 {{did you mean to use 'try'?}}
  // expected-note@-4 {{did you mean to handle error as optional value?}}
  // expected-note@-5 {{did you mean to disable error propagation?}}
  return x
}

func tryDo8() throws -> Int {
  return try do { try tryDo4() }
  // expected-warning@-1 {{'try' has no effect on 'do' expression}}
}

func tryDo9() throws -> Int {
  try do { try tryDo4() }
  // expected-warning@-1 {{'try' has no effect on 'do' expression}}
}

func tryDo10() throws -> Int {
  let x = try do { try tryDo4() }
  // expected-warning@-1 {{'try' has no effect on 'do' expression}}
  return x
}

func tryDo11() throws -> Int {
  let x = try do { try tryDo4() } catch { tryDo4() }
  // expected-warning@-1 {{'try' has no effect on 'do-catch' expression}}
  // expected-warning@-2 {{call can throw but is not marked with 'try'; this is an error in the Swift 6 language mode}}
  // expected-note@-3 {{did you mean to use 'try'?}}
  // expected-note@-4 {{did you mean to handle error as optional value?}}
  // expected-note@-5 {{did you mean to disable error propagation?}}
  return x
}

func tryDo12() throws -> Int {
  let x = try do { tryDo4() } catch { tryDo4() }
  // expected-warning@-1 {{'try' has no effect on 'do-catch' expression}}
  // expected-warning@-2 2{{call can throw but is not marked with 'try'; this is an error in the Swift 6 language mode}}
  // expected-note@-3 2{{did you mean to use 'try'?}}
  // expected-note@-4 2{{did you mean to handle error as optional value?}}
  // expected-note@-5 2{{did you mean to disable error propagation?}}
  return x
}

func tryDo13() throws -> Int {
  let x = try do { // expected-warning {{'try' has no effect on 'do-catch' expression}}
    tryDo4() // expected-warning {{result of call to 'tryDo4()' is unused}}
    // expected-warning@-1 {{call can throw but is not marked with 'try'; this is an error in the Swift 6 language mode}}
    // expected-note@-2 {{did you mean to use 'try'?}}
    // expected-note@-3 {{did you mean to handle error as optional value?}}
    // expected-note@-4 {{did you mean to disable error propagation?}}

    _ = tryDo4()
    // expected-warning@-1 {{call can throw but is not marked with 'try'; this is an error in the Swift 6 language mode}}
    // expected-note@-2 {{did you mean to use 'try'?}}
    // expected-note@-3 {{did you mean to handle error as optional value?}}
    // expected-note@-4 {{did you mean to disable error propagation?}}

    _ = try tryDo4() // Okay.

    // Okay.
    do {
      _ = try tryDo4()
    } catch {}

    print("hello")
    throw Err()
  } catch _ where .random() {
    0
  } catch {
    throw error
  }
  return x
}

func throwsBool() throws -> Bool { true }

func tryDo14() throws -> Int {
  try do { try tryDo4() } catch _ where throwsBool() { 0 } catch { 1 }
  // expected-warning@-1 {{'try' has no effect on 'do-catch' expression}}
  // expected-error@-2 {{call can throw, but errors cannot be thrown out of a catch guard expression}}
}

func tryDo15() throws -> Int {
  try do { try tryDo4() } catch _ where try throwsBool() { 1 } catch { 1 }
  // expected-warning@-1 {{'try' has no effect on 'do-catch' expression}}
  // expected-error@-2 {{call can throw, but errors cannot be thrown out of a catch guard expression}}
}

func tryDo16() throws -> Int {
  do { try tryDo4() } catch _ where throwsBool() { 0 } catch { 1 }
  // expected-error@-1 {{call can throw, but errors cannot be thrown out of a catch guard expression}}
}

func tryDo17() throws -> Int {
  do { tryDo4() } catch { 1 }
  // expected-error@-1 {{call can throw but is not marked with 'try'}}
  // expected-note@-2 {{did you mean to use 'try'?}}
  // expected-note@-3 {{did you mean to handle error as optional value?}}
  // expected-note@-4 {{did you mean to disable error propagation?}}
}

func tryDo18() {
  // Make sure we don't warn here.
  do {
    let _ = do { try tryDo4() }
  } catch {}
}

func tryDo19() {
  // Make sure we don't warn here.
  do {
    let _ = do { throw Err() }
  } catch {}
}

func tryDo19() throws -> Int {
  let x = do { try tryDo4() } catch { throw Err() }
  return x
}

func tryDo20() throws -> Int {
  do { try tryDo4() } catch { throw Err() }
}

func tryDo21(_ fn: () throws -> Int) rethrows -> Int {
  let x = do { try fn() }
  return x
}

func tryDo22(_ fn: () throws -> Int) rethrows -> Int {
  do { try fn() }
}

func tryDo23(_ fn: () throws -> Int) rethrows -> Int {
  // Fine, we can only end up in the 'catch' if we rethrow in the first place.
  let x = do { try fn() } catch { throw Err() }
  return x
}

func tryDo23_2(_ fn: () throws -> Int) rethrows -> Int {
  let x = do { try tryDo4() } catch _ where .random() { try fn() } catch { throw Err() }
  // expected-error@-1 {{a function declared 'rethrows' may only throw if its parameter does}}
  return x
}

func tryDo24(_ fn: () throws -> Int) rethrows -> Int {
  // Fine, we can only end up in the 'catch' if we rethrow in the first place.
  let x = do { try fn() } catch { try tryDo4() }
  return x
}

func tryDo24_2(_ fn: () throws -> Int) rethrows -> Int {
  let x = do { try tryDo4() } catch _ where .random() { try fn() } catch { try tryDo4() }
  // expected-error@-1 {{call can throw, but the error is not handled; a function declared 'rethrows' may only throw if its parameter does}}
  return x
}

func tryDo25(_ fn: () throws -> Int) rethrows -> Int {
  do {
    let x = do { try fn() } catch { try tryDo4() }
    return x
  } catch {
    return 0
  }
}

func tryDo26(_ fn: () throws -> Int) rethrows -> Int {
  do {
    let x = do { try fn() } catch { throw Err() }
    return x
  } catch {
    return 0
  }
}

func tryDo27(_ fn: () throws -> Int) rethrows -> Int {
  do {
    let x = do { try fn() } catch { try tryDo4() }
    return x
  } catch {
    throw error  // expected-error {{a function declared 'rethrows' may only throw if its parameter does}}
  }
}

func tryDo28(_ fn: () throws -> Int) rethrows -> Int {
  do {
    let x = do { try fn() } catch { throw Err() }
    return x
  } catch {
    throw error  // expected-error {{a function declared 'rethrows' may only throw if its parameter does}}
  }
}

func tryDo29(_ fn: () throws -> Int) rethrows -> Int {
  do {
    let x = do { try fn() }
    return x
  } catch {
    throw error // Okay.
  }
}

func tryDo30(_ fn: () throws -> Int) rethrows -> Int {
  // FIXME: This ought to work (https://github.com/apple/swift/issues/68824)
  do {
    let x = do { try fn() } catch { throw error }
    return x
  } catch {
    throw error // expected-error {{a function declared 'rethrows' may only throw if its parameter does}}
  }
}

func awaitDo1() async -> Int {
  await do { 0 }
  // expected-warning@-1 {{'await' has no effect on 'do' expression}}
}

func awaitDo2() async -> Int {
  let x = await do { 0 }
  // expected-warning@-1 {{'await' has no effect on 'do' expression}}
  return x
}

func awaitDo3() -> Int { // expected-note {{add 'async' to function 'awaitDo3()' to make it asynchronous}}
  return await do { 0 }
  // expected-error@-1 {{'await' in a function that does not support concurrency}}
}

func awaitDo4() async -> Int {
  return await do { 0 }
  // expected-warning@-1 {{'await' has no effect on 'do' expression}}
}

func awaitDo5() async -> Int {
  return await do { awaitDo4() }
  // expected-warning@-1 {{'await' has no effect on 'do' expression}}
  // expected-warning@-2 {{expression is 'async' but is not marked with 'await'}}
  // expected-note@-3 {{call is 'async'}}
}

func awaitDo6() async -> Int {
  await do { awaitDo4() }
  // expected-warning@-1 {{'await' has no effect on 'do' expression}}
  // expected-warning@-2 {{expression is 'async' but is not marked with 'await'}}
  // expected-note@-3 {{call is 'async'}}
}

func awaitDo7() async -> Int {
  let x = await do { awaitDo4() }
  // expected-warning@-1 {{'await' has no effect on 'do' expression}}
  // expected-warning@-2 {{expression is 'async' but is not marked with 'await'}}
  // expected-note@-3 {{call is 'async'}}
  return x
}

func awaitDo8() async -> Int {
  return await do { await awaitDo4() }
  // expected-warning@-1 {{'await' has no effect on 'do' expression}}
}

func awaitDo9() async -> Int {
  await do { await awaitDo4() }
  // expected-warning@-1 {{'await' has no effect on 'do' expression}}
}

func awaitDo10() async -> Int {
  let x = await do { await awaitDo4() }
  // expected-warning@-1 {{'await' has no effect on 'do' expression}}
  return x
}

func awaitDo11() async -> Int {
  let x = await do { try await tryAwaitDo1() } catch { awaitDo4() }
  // expected-warning@-1 {{'await' has no effect on 'do-catch' expression}}
  // expected-warning@-2 {{expression is 'async' but is not marked with 'await'; this is an error in the Swift 6 language mode}}
  // expected-note@-3 {{call is 'async'}}
  return x
}

func awaitDo12() async -> Int {
  let x = await do { try tryAwaitDo1() } catch { awaitDo4() }
  // expected-warning@-1 {{'await' has no effect on 'do-catch' expression}}
  // expected-warning@-2 2{{expression is 'async' but is not marked with 'await'; this is an error in the Swift 6 language mode}}
  // expected-note@-3 2{{call is 'async'}}
  return x
}

func awaitDo13() async throws -> Int {
  let x = await do { // expected-warning {{'await' has no effect on 'do-catch' expression}}
    awaitDo4() // expected-warning {{result of call to 'awaitDo4()' is unused}}
    // expected-warning@-1 {{expression is 'async' but is not marked with 'await'; this is an error in the Swift 6 language mode}}
    // expected-note@-2 {{call is 'async'}}

    _ = awaitDo4()
    // expected-warning@-1 {{expression is 'async' but is not marked with 'await'; this is an error in the Swift 6 language mode}}
    // expected-note@-2 {{call is 'async'}}

    _ = await awaitDo4() // Okay.

    // Okay.
    let _ = {
      _ = await awaitDo4()
    }

    print("hello")
    throw Err()
  } catch _ where .random() {
    0
  } catch {
    throw error
  }
  return x
}

func asyncBool() async -> Bool { true }

func awaitDo14() async -> Int {
  await do { try tryDo4() } catch _ where asyncBool() { 0 } catch { 1 }
  // expected-warning@-1 {{'await' has no effect on 'do-catch' expression}}
  // expected-error@-2 {{'async' call cannot occur in a catch guard expression}}
}

func awaitDo15() async -> Int {
  await do { try tryDo4() } catch _ where await asyncBool() { 0 } catch { 1 }
  // expected-warning@-1 {{'await' has no effect on 'do-catch' expression}}
  // expected-error@-2 {{'async' call cannot occur in a catch guard expression}}
}

func awaitDo16() async -> Int {
  do { try tryDo4() } catch _ where asyncBool() { 0 } catch { 1 }
  // expected-error@-1 {{'async' call cannot occur in a catch guard expression}}
}

func awaitDo17() async -> Int {
  do { awaitDo4() }
  // expected-error@-1 {{expression is 'async' but is not marked with 'await'}}
  // expected-note@-2 {{call is 'async'}}
}

func awaitDo18() {
  let _ = {
    let _ = do { await awaitDo4() }
  }
}

func awaitDo19() async -> Int {
  let x = do { await awaitDo4() }
  return x
}

func awaitDo20() async -> Int {
  do { await awaitDo4() }
}

func tryAwaitDo1() async throws -> Int {
  try await do { 0 }
  // expected-warning@-1 {{'try' has no effect on 'do' expression}}
  // expected-warning@-2 {{'await' has no effect on 'do' expression}}
}

func tryAwaitDo2() async throws -> Int {
  try await do { 0 } as Int
  // expected-warning@-1 {{'try' has no effect on 'do' expression}}
  // expected-warning@-2 {{'await' has no effect on 'do' expression}}
}

func tryAwaitDo3() async throws -> Int {
  try await do { tryAwaitDo2() } as Int
  // expected-warning@-1 {{'try' has no effect on 'do' expression}}
  // expected-warning@-2 {{'await' has no effect on 'do' expression}}
  // expected-warning@-3 {{call can throw but is not marked with 'try'; this is an error in the Swift 6 language mode}}
  // expected-note@-4 {{did you mean to use 'try'?}}
  // expected-note@-5 {{did you mean to handle error as optional value?}}
  // expected-note@-6 {{did you mean to disable error propagation?}}
  // expected-warning@-7 {{expression is 'async' but is not marked with 'await'; this is an error in the Swift 6 language mode}}
  // expected-note@-8 {{call is 'async'}}
}

func tryAwaitDo4() async throws -> Int {
  try await do { try tryAwaitDo2() } as Int
  // expected-warning@-1 {{'try' has no effect on 'do' expression}}
  // expected-warning@-2 {{'await' has no effect on 'do' expression}}
  // expected-warning@-3 {{expression is 'async' but is not marked with 'await'; this is an error in the Swift 6 language mode}}
  // expected-note@-4 {{call is 'async'}}
}

func tryAwaitDo5() async throws -> Int {
  try await do { await tryAwaitDo2() } as Int
  // expected-warning@-1 {{'try' has no effect on 'do' expression}}
  // expected-warning@-2 {{'await' has no effect on 'do' expression}}
  // expected-warning@-3 {{call can throw but is not marked with 'try'; this is an error in the Swift 6 language mode}}
  // expected-note@-4 {{did you mean to use 'try'?}}
  // expected-note@-5 {{did you mean to handle error as optional value?}}
  // expected-note@-6 {{did you mean to disable error propagation?}}
}

func tryAwaitDo6() async throws -> Int {
  try await do { try await tryAwaitDo2() } as Int
  // expected-warning@-1 {{'try' has no effect on 'do' expression}}
  // expected-warning@-2 {{'await' has no effect on 'do' expression}}
}

func tryAwaitDo7() async throws -> Int {
  try await do { tryAwaitDo2() }
  // expected-warning@-1 {{'try' has no effect on 'do' expression}}
  // expected-warning@-2 {{'await' has no effect on 'do' expression}}
  // expected-warning@-3 {{call can throw but is not marked with 'try'; this is an error in the Swift 6 language mode}}
  // expected-note@-4 {{did you mean to use 'try'?}}
  // expected-note@-5 {{did you mean to handle error as optional value?}}
  // expected-note@-6 {{did you mean to disable error propagation?}}
  // expected-warning@-7 {{expression is 'async' but is not marked with 'await'; this is an error in the Swift 6 language mode}}
  // expected-note@-8 {{call is 'async'}}
}

func tryAwaitDo8() async throws -> Int {
  try await do { try tryAwaitDo2() }
  // expected-warning@-1 {{'try' has no effect on 'do' expression}}
  // expected-warning@-2 {{'await' has no effect on 'do' expression}}
  // expected-warning@-3 {{expression is 'async' but is not marked with 'await'; this is an error in the Swift 6 language mode}}
  // expected-note@-4 {{call is 'async'}}
}

func tryAwaitDo9() async throws -> Int {
  try await do { await tryAwaitDo2() }
  // expected-warning@-1 {{'try' has no effect on 'do' expression}}
  // expected-warning@-2 {{'await' has no effect on 'do' expression}}
  // expected-warning@-3 {{call can throw but is not marked with 'try'; this is an error in the Swift 6 language mode}}
  // expected-note@-4 {{did you mean to use 'try'?}}
  // expected-note@-5 {{did you mean to handle error as optional value?}}
  // expected-note@-6 {{did you mean to disable error propagation?}}
}

func tryAwaitDo10() async throws -> Int {
  try await do { try await tryAwaitDo2() }
  // expected-warning@-1 {{'try' has no effect on 'do' expression}}
  // expected-warning@-2 {{'await' has no effect on 'do' expression}}
}

func tryAwaitDo11(_ fn: () async throws -> Int) async rethrows -> Int {
  do {
    let x = do { try await fn() } catch { try await tryAwaitDo4() }
    return x
  } catch {
    return 0
  }
}

func tryAwaitDo12(_ fn: () async throws -> Int) async rethrows -> Int {
  do {
    let x = do { try await fn() } catch { throw Err() }
    return x
  } catch {
    return 0
  }
}

func tryAwaitDo13(_ fn: () async throws -> Int) async rethrows -> Int {
  do {
    let x = do { try await fn() } catch { try await tryAwaitDo4() }
    return x
  } catch {
    throw error  // expected-error {{a function declared 'rethrows' may only throw if its parameter does}}
  }
}

func tryAwaitDo14(_ fn: () async throws -> Int) async rethrows -> Int {
  do {
    let x = do { try await fn() } catch { throw Err() }
    return x
  } catch {
    throw error  // expected-error {{a function declared 'rethrows' may only throw if its parameter does}}
  }
}

func tryAwaitDo15(_ fn: () async throws -> Int) async rethrows -> Int {
  // FIXME: This ought to work (https://github.com/apple/swift/issues/68824)
  do {
    let x = do { try await fn() } catch { throw error }
    return x
  } catch {
    throw error // expected-error {{a function declared 'rethrows' may only throw if its parameter does}}
  }
}