sourcekit-lsp icon indicating copy to clipboard operation
sourcekit-lsp copied to clipboard

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

Open jm-alan opened this issue 2 years ago • 3 comments

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

jm-alan avatar Dec 06 '23 11:12 jm-alan

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

ahoppen avatar Dec 06 '23 13:12 ahoppen

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

ahoppen avatar Dec 06 '23 17:12 ahoppen

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.

MaxDesiatov avatar Dec 06 '23 17:12 MaxDesiatov

Looks like Sendable conformance to NSLock was added recently to swift-corelibs-foundation, which is used on Linux: https://github.com/apple/swift-corelibs-foundation/pull/4944

ahoppen avatar Jun 04 '24 04:06 ahoppen