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
Attachment: Download
md5: 2e59f16869dc5cd2056f09f72289da88
Issue Description:
Having the code:
import UIKit class ViewController: UIViewController { private let presenter: Presenter required init?(coder: NSCoder) { let presenter = Presenter() self.presenter = presenter super.init(coder: coder) presenter.view = self } override func viewDidLoad() { super.viewDidLoad() print("did load") presenter.doSmth() } } extension ViewController { @MainActor func doSmthOnMain() { dispatchPrecondition(condition: .onQueue(.main)) } } final class Presenter { @MainActor weak var view: ViewController? func doSmth() { Task { await view?.doSmthOnMain() } } }
application crashes on the line:
dispatchPrecondition(condition: .onQueue(.main))
If you run the project attached, you will see that @mainactor isolation is not ensured and this method is called from cooperative queue.
Interestingly, if I delete @mainactor from the declaration:
@MainActor weak var view: ViewInternal?
Method is ensured to be run on main, so no crash.
The text was updated successfully, but these errors were encountered:
Comment by Ivan Sobolevskiy (JIRA)
I further simplified the case and attached a new one.
Interestingly, if we remove 'final' from 'Presenter' declaration, everything works fine. So it seems because of some optimisation Main actor isolation is not ensured
Sorry, something went wrong.
@swift-ci create
Fixed in Swift 5.6 #41176
Thank you for the report.
kavon
No branches or pull requests
Attachment: Download
Additional Detail from JIRA
md5: 2e59f16869dc5cd2056f09f72289da88
Issue Description:
Having the code:
application crashes on the line:
If you run the project attached, you will see that @mainactor isolation is not ensured and this method is called from cooperative queue.
Interestingly, if I delete @mainactor from the declaration:
Method is ensured to be run on main, so no crash.
The text was updated successfully, but these errors were encountered: