- Notifications
You must be signed in to change notification settings - Fork 10.6k
Open
Labels
@mainFeature → attributes: the @main attributeFeature → attributes: the @main attributeactorFeature → concurrency: `actor` declarationsFeature → concurrency: `actor` declarationsactor isolationFeature → concurrency: Actor isolationFeature → concurrency: Actor isolationattributesFeature: Declaration and type attributesFeature: Declaration and type attributesbugA 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 itselfconcurrencyFeature: umbrella label for concurrency language featuresFeature: umbrella label for concurrency language featuresconformancesFeature → protocol: protocol conformancesFeature → protocol: protocol conformancesdeclarationsFeature: declarationsFeature: declarationsdefault implementationsFeature → protocol → conformances: default implementationsFeature → protocol → conformances: default implementationsextensionFeature → declarations: `extension` declarationsFeature → declarations: `extension` declarationsprotocolFeature → type declarations: Protocol declarationsFeature → type declarations: Protocol declarationsswift 5.9type checkerArea → compiler: Semantic analysisArea → compiler: Semantic analysisunexpected behaviorBug: Unexpected behavior or incorrect outputBug: Unexpected behavior or incorrect output
Description
Description
The main function is not MainActor if it is provided by an extension function by conforming to a protocol.
Steps to reproduce
import Foundation @main struct Test: P { } protocol P {} extension P { static func main() async { print(Thread.isMainThread) // prints false } }import Foundation @main struct Test: P { static func main() async { print(Thread.isMainThread) // prints true } } protocol P {} extension P { }Expected behavior
If I understand SE-0323 correctly, both code should print true, since main function should be implicitly MainActor.
Environment
swift-driver version: 1.75.2 Apple Swift version 5.8 (swiftlang-5.8.0.124.2 clang-1403.0.22.11.100)
Target: arm64-apple-macosx13.0
Xcode 14.3
Build version 14E222b
Additional context
I encountered this problem while using Swift Argument Parser. The original code is something like this:
@main struct Command: AsyncParsableCommand { @MainActor func run() async throws { // App is a SwiftUI App App.main() } }The code works in an old version of Xcode (~13.x), but failed with Fatal error: calling into SwiftUI on a non-main thread is not supported when upgrading to 14.x.
Metadata
Metadata
Assignees
Labels
@mainFeature → attributes: the @main attributeFeature → attributes: the @main attributeactorFeature → concurrency: `actor` declarationsFeature → concurrency: `actor` declarationsactor isolationFeature → concurrency: Actor isolationFeature → concurrency: Actor isolationattributesFeature: Declaration and type attributesFeature: Declaration and type attributesbugA 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 itselfconcurrencyFeature: umbrella label for concurrency language featuresFeature: umbrella label for concurrency language featuresconformancesFeature → protocol: protocol conformancesFeature → protocol: protocol conformancesdeclarationsFeature: declarationsFeature: declarationsdefault implementationsFeature → protocol → conformances: default implementationsFeature → protocol → conformances: default implementationsextensionFeature → declarations: `extension` declarationsFeature → declarations: `extension` declarationsprotocolFeature → type declarations: Protocol declarationsFeature → type declarations: Protocol declarationsswift 5.9type checkerArea → compiler: Semantic analysisArea → compiler: Semantic analysisunexpected behaviorBug: Unexpected behavior or incorrect outputBug: Unexpected behavior or incorrect output