8000 Default main actor prevents synthesized struct initializer from being seen · Issue #82168 · swiftlang/swift · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Default main actor prevents synthesized struct initializer from being seen #82168

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

Open
stephencelis opened this issue Jun 10, 2025 · 0 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. triage needed This issue needs more specific labels

Comments

@stephencelis
Copy link
Contributor

Description

I've been exploring default main actor implications on some of our packages and have hit a peculiar one.

Reproduction

nonisolated protocol P {
  associatedtype AT
  static var at: AT { get }
}

nonisolated struct KP<R: P, V> {
  init(keyPath: KeyPath<R, V>) {}
}

struct S: P {
  let p: Int
  struct AT {
    let kp = KP(keyPath: \S.p)
  }
  static let at = AT()  // 🛑
}

'S.AT' cannot be constructed because it has no accessible initializers

Workaround: Add an explicit init() {} to the nested AT struct.

Expected behavior

I expect it to compile, since it does outside of default main actor mode:

nonisolated protocol P {
  associatedtype AT
  static var at: AT { get }
}

nonisolated struct KP<R: P, V> {
  init(keyPath: KeyPath<R, V>) {}
}

@MainActor
struct S: @MainActor P {
  let p: Int
  @MainActor
  struct AT {
    let kp = KP(keyPath: \S.p)
  }
  static let at = AT()
}

Environment

Apple Swift version 6.2-dev (LLVM 9ae4b59a6edd27c, Swift 9b6c04e)
Target: arm64-apple-macosx15.0
Build config: +assertions

Additional information

No response

@stephencelis stephencelis added bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. triage needed This issue needs more specific labels labels Jun 10, 2025
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. triage needed This issue needs more specific labels
Projects
None yet
Development

No branches or pull requests

1 participant
0