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-15694] @MainActor doesn't cascade to init in class #57973

Closed
keith opened this issue Jan 6, 2022 · 2 comments
Closed

[SR-15694] @MainActor doesn't cascade to init in class #57973

keith opened this issue Jan 6, 2022 · 2 comments
Assignees
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior.

Comments

@keith
Copy link
Collaborator

keith commented Jan 6, 2022

Previous ID SR-15694
Radar rdar://problem/87217618
Original Reporter @keith
Type Bug
Status Resolved
Resolution Done
Additional Detail from JIRA
Votes 0
Component/s
Labels Bug
Assignee @kavon
Priority Medium

md5: df5f376c11c24d77b7e241a9c0d14f7a

Issue Description:

With this source:

import Foundation
import UIKit

@MainActor
class Foo: UIView {
    init() {
        super.init(frame: .zero)
    }

    required init?(coder: NSCoder) {
        fatalError()
    }
}

I would expect that everything in `Foo` was constrained to the `MainActor`, but this produces this error with the 2021-12-23 main snapshot (org.swift.50202112231a):

% TOOLCHAINS=org.swift.50202112231a xcrun swiftc /tmp/foo2.swift -sdk /Applications/Xcode-13.0.0-RC1.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator15.0.sdk -target x86_64-apple-ios12.0-simulator
/tmp/foo2.swift:7:15: error: call to main actor-isolated initializer 'init(frame:)' in a synchronous nonisolated context
        super.init(frame: .zero)
              ^
UIKit.UIView:4:12: note: calls to initializer 'init(frame:)' from outside of its actor context are implicitly asynchronous
    public init(frame: CGRect)
           ^

Marking the `init` function with `MainActor` as well as the class fixes this

@kavon
Copy link
Contributor

kavon commented Jan 6, 2022

@swift-ci create

@kavon
Copy link
Contributor

kavon commented Mar 30, 2022

resolved in #41662

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
This issue was closed.
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.
Projects
None yet
Development

No branches or pull requests

2 participants