apple / sourcekit-lsp

Language Server Protocol implementation for Swift and C-based languages

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`NSLock` triggers a warning when a containing struct is `Sendable` even though `NSLock` conforms to `Sendable`

jm-alan opened this issue · comments

commented

When creating a struct with an internal NSLock, e.g.

struct MyLockWrapper {
    let lock: NSLock = .init()
}

and confirming this struct to Sendable

extension MyLockWrapper: Sendable {}

SourceKitD generates the following warning about NSLock not conforming to Sendable:
stored property 'lock' of 'Sendable'-conforming struct 'MyLockWrapper' has non-sendable type 'NSLock'

Even though the Apple developer documentation explicitly says it does

Tracked in Apple’s issue tracker as rdar://119250614

Do you also see this warning during compilation? And: Which version of swift/sourcekit-lsp are you using?

This could also be platform-dependent, Apple documentation doesn't cover swift-corelibs-libdispatch, which largely lacks Sendable annotations for vast majority of its types.

Looks like Sendable conformance to NSLock was added recently to swift-corelibs-foundation, which is used on Linux: apple/swift-corelibs-foundation#4944