Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SR-15703] MainActor isolation fails when synthesized async function (from Objective-C method) throws an error #57982

Closed
toddreed opened this issue Jan 7, 2022 · 5 comments · Fixed by #58474
Assignees
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself

Comments

@toddreed
Copy link

toddreed commented Jan 7, 2022

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.0
Additional 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 MainActorBug
@kavon
Copy link
Contributor

kavon commented Feb 24, 2022

@swift-ci create

@kavon
Copy link
Contributor

kavon commented Feb 24, 2022

Bug confirmed to be present in `main` as of today.

@kavon
Copy link
Contributor

kavon commented Feb 26, 2022

fix is here: #41571

@kavon
Copy link
Contributor

kavon commented Mar 1, 2022

fixed in #41571

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@kavon
Copy link
Contributor

kavon commented Apr 26, 2022

The implementation of this fix introduced a regression. It has been reverted in #58397 , so I'm reopening this issue until that is resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants