Open
Description
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