Skip to content

Commit db0a67b

Browse files
committed
Add sendable annotation to userInfo closure
swift-foundation recently landed a change (in swiftlang/swift-foundation#764) which requires `any Sendable` values in `JSONEncoder.userInfo`. This causes a build failure: ``` JSONRPCConnection.swift:370:50: error: type '(RequestID) -> Optional<any ResponseType.Type>' does not conform to the 'Sendable' protocol 368 | 369 | // Setup callback for response type. 370 | decoder.userInfo[.responseTypeCallbackKey] = { (id: RequestID) -> ResponseType.Type? in | |- error: type '(RequestID) -> Optional<any ResponseType.Type>' does not conform to the 'Sendable' protocol | `- note: a function type must be marked '@sendable' to conform to 'Sendable' 371 | guard let outstanding = self.outstandingRequests[id] else { 372 | logger.error("Unknown request for \(id, privacy: .public)") ``` Make the closure sendable, which is safe as we're only reading from `outstandingRequests` (where all our writes are guarded by the same queue that the decoding is on).
1 parent 94ba7ea commit db0a67b

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

Sources/LanguageServerProtocolJSONRPC/JSONRPCConnection.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,9 @@ public final class JSONRPCConnection: Connection {
367367
decoder.userInfo[.messageRegistryKey] = messageRegistry
368368

369369
// Setup callback for response type.
370-
decoder.userInfo[.responseTypeCallbackKey] = { (id: RequestID) -> ResponseType.Type? in
370+
decoder.userInfo[.responseTypeCallbackKey] = { @Sendable (id: RequestID) -> ResponseType.Type? in
371+
// `outstandingRequests` should never be mutated in this closure. Reading is fine as all of our other writes are
372+
// guarded by `queue`, but `JSONDecoder` could (since this is sendable) invoke this concurrently.
371373
guard let outstanding = self.outstandingRequests[id] else {
372374
logger.error("Unknown request for \(id, privacy: .public)")
373375
return nil

Sources/SKTestSupport/CheckCoding.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ package func checkDecoding<T: Codable & Equatable>(
9595
package func checkCoding<T: Codable>(
9696
_ value: T,
9797
json: String,
98-
userInfo: [CodingUserInfoKey: Any] = [:],
98+
userInfo: [CodingUserInfoKey: any Sendable] = [:],
9999
file: StaticString = #filePath,
100100
line: UInt = #line,
101101
body: (T) -> Void

0 commit comments

Comments
 (0)