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

MainActor-isolated property not called on the Main Actor #72633

Open
okla opened this issue Mar 27, 2024 · 0 comments
Open

MainActor-isolated property not called on the Main Actor #72633

okla opened this issue Mar 27, 2024 · 0 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. concurrency Feature: umbrella label for concurrency language features

Comments

@okla
Copy link

okla commented Mar 27, 2024

Description

Reproduction code works on both iOS and MacOS. Since SwiftUI.App.body is MainActor-isolated, nonIsolatedSyncProperty also called on the Main Actor because it's sync, but its task is non-isolated and called not on the Main Actor, but then it calls MainActor-isolated isolatedGlobalSyncProperty and it crashes because it's called not on the Main Actor for some reason.

Reproduction

import SwiftUI

@MainActor var isolatedGlobalSyncProperty: Void {
  MainActor.assertIsolated("Isolated global sync property called not on the Main Actor")
}

@main
struct SwiftConcurrencyApp: App {
  var nonIsolatedSyncProperty: some View {
    Text("Hello")
      .task {
        await isolatedGlobalSyncProperty
      }
  }

  var body: some Scene {
    WindowGroup {
      nonIsolatedSyncProperty
    }
  }
}

Expected behavior

isolatedGlobalSyncProperty called on the Main Actor.

Environment

swift-driver version: 1.90.11.1 Apple Swift version 5.10 (swiftlang-5.10.0.13 clang-1500.3.9.4)
Target: x86_64-apple-macosx14.0

Additional information

Reproduction code results in a crash with output: SwiftConcurrencyMac/SwiftConcurrencyMacApp.swift:11: Fatal error: Incorrect actor executor assumption; Expected 'UnownedSerialExecutor(executor: (Opaque Value))' executor. Isolated global sync property called not on the Main Actor

@okla okla added bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. triage needed This issue needs more specific labels labels Mar 27, 2024
@hborla hborla added concurrency Feature: umbrella label for concurrency language features and removed triage needed This issue needs more specific labels labels Apr 27, 2024
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. concurrency Feature: umbrella label for concurrency language features
Projects
None yet
Development

No branches or pull requests

2 participants