mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Previously we allowed an attached `try` or `await` on an `if`/`switch` expression to cover the branches, which does not match what was proposed, and is especially harmful for multi-statement cases. Fix the effect handling logic such that we reset effect coverage for `if`/`switch` expressions similar to closures, but continue to maintain the state needed for rethrows checking. rdar://116066748
33 lines
993 B
Swift
33 lines
993 B
Swift
// RUN: %target-typecheck-verify-swift -disable-availability-checking -enable-experimental-concurrency
|
|
|
|
// Required for '-enable-experimental-concurrency'
|
|
// REQUIRES: concurrency
|
|
// REQUIRES: asserts
|
|
|
|
func asyncFn() async -> Int { 0 }
|
|
|
|
func reasyncIf1(_ fn: () async -> Int) reasync -> Int {
|
|
let x = if .random() { await fn() } else { 1 }
|
|
return x
|
|
}
|
|
|
|
func reasyncIf2(_ fn: () async -> Int) reasync -> Int {
|
|
if .random() { await fn() } else { 1 }
|
|
}
|
|
|
|
// Not a very good diagnostic, but reasync is still experimental.
|
|
func reasyncIf3(_ fn: () async -> Int) reasync -> Int {
|
|
// expected-note@-1 {{add 'async' to function 'reasyncIf3' to make it asynchronous}}
|
|
let x = if .random() { await fn() } else { await asyncFn() }
|
|
// expected-error@-1 {{'async' call in a function that does not support concurrency}}
|
|
return x
|
|
}
|
|
|
|
func reasyncIf4(_ fn: () async -> Int) reasync -> Int {
|
|
let _ = {
|
|
let x = if .random() { await fn() } else { await asyncFn() }
|
|
return x
|
|
}
|
|
return 0
|
|
}
|