-
Notifications
You must be signed in to change notification settings - Fork 10.6k
Closed
Labels
bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.A deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselfThe Swift compiler itself
Description
| Previous ID | SR-15703 |
| Radar | rdar://89479707 |
| Original Reporter | @toddreed |
| Type | Bug |
| Status | Resolved |
| Resolution | Done |
Attachment: Download
Environment
swift -version
swift-driver version: 1.26.21 Apple Swift version 5.5.2 (swiftlang-1300.0.47.5 clang-1300.0.29.30)
Target: x86_64-apple-macosx12.0Additional Detail from JIRA
| Votes | 0 |
| Component/s | Compiler |
| Labels | Bug |
| Assignee | @kavon |
| Priority | Medium |
md5: c52cb58ce3c02bb5270368dfb10304f1
Issue Description:
When calling a synthesized async function (i.e. synthesize from an Objective-C method) from a @mainactor function in Swift, execution resumes on a background thread instead of the main thread when the function throws an error.
Example: in the code the below, the assertion in the catch block fails.
@main
class MainActorBug {
@MainActor
static func main() async {
let adder = Adder()
do {
let result = try await adder.add(-5)
assert(Thread.isMainThread)
print("The answer is \(result)")
} catch {
assert(Thread.isMainThread, "Not on main thread")
print(error)
}
}
}To reproduce:
unzip MainActorBug.zip
cd MainActorBug
swift run MainActorBugMetadata
Metadata
Assignees
Labels
bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.A deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselfThe Swift compiler itself