swift icon indicating copy to clipboard operation
swift copied to clipboard

Appending a writable/sendable key path loses writability

Open stephencelis opened this issue 1 year ago • 3 comments

Description

The new sendable key path diagnostics seems to lose writability when appending a sendable, writable key path.

Reproduction

struct S {
  var p = 0
}
struct T {
  var s = S()
}
func f() {
  let kp1: WritableKeyPath<T, S> & Sendable = \T.s
  let kp2: WritableKeyPath<T, Int> & Sendable = kp1.appending(path: \.p)
}

Expected behavior

kp2 should compile, but we get:

Error: Cannot convert value of type 'KeyPath<T, Int>' to specified type 'WritableKeyPath<T, Int>'

Environment

swift-driver version: 1.112.3 Apple Swift version 6.0 (swiftlang-6.0.0.6.8 clang-1600.0.23.1) Target: arm64-apple-macosx14.0

Additional information

No response

stephencelis avatar Jul 28 '24 06:07 stephencelis

@xedin Another one. Sorry! 🙈

stephencelis avatar Jul 28 '24 06:07 stephencelis

I think this is a stdlib problem, we discussed this in the proposal - https://github.com/swiftlang/swift-evolution/blob/main/proposals/0418-inferring-sendable-for-methods.md#extending-key-path-merging-functionality-to-preserve-sendability.

xedin avatar Jul 28 '24 07:07 xedin

Also thank you for the reports, no need to be sorry!

xedin avatar Jul 28 '24 07:07 xedin