6.0 Strict Concurrency Warning when KeyPath marked as Sendable

Hi! I'm working with some KeyPath types and Strict Concurrency. I'm seeing some warnings and trying to following along with SE-0418[1]… but I'm not sure I understand how I can make the compiler happy.

Here is a (simple) example:

struct User {
  var name: String
}

let name: KeyPath<User, String> & Sendable = \.name
// warning: Type 'WritableKeyPath<User, String>' does not conform to the 'Sendable' protocol; this is an error in the Swift 6 language mode

My understanding (from SE-0418) is this explicit adoption of Sendable should be ok… is there something I am missing here?

This is building from Xcode 16.0 beta (16A5171c). My swift package requires 6.0 and adds enableExperimentalFeature("StrictConcurrency").


  1. swift-evolution/proposals/0418-inferring-sendable-for-methods.md at main · swiftlang/swift-evolution · GitHub ↩︎

3 Likes

It sounds like the upcoming feature from SE-0418 is not enabled. Try adding .enableUpcomingFeature("InferSendableFromCaptures") to your package manifest

4 Likes

Ahh… correct! That fixes the warning. Thanks!