Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid sendable key paths in dynamic member lookup #3463

Merged
merged 2 commits into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 65 additions & 9 deletions Sources/ComposableArchitecture/Internal/KeyPath+Sendable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,69 @@
public typealias _SendableCaseKeyPath<Root, Value> = CaseKeyPath<Root, Value>
#endif

@_transparent
func sendableKeyPath(
_ keyPath: AnyKeyPath
) -> _SendableAnyKeyPath {
#if compiler(>=6)
unsafeBitCast(keyPath, to: _SendableAnyKeyPath.self)
#else
keyPath
#endif
// NB: Dynamic member lookup does not currently support sendable key paths and even breaks
// autocomplete.
//
// * https://github.com/swiftlang/swift/issues/77035
// * https://github.com/swiftlang/swift/issues/77105
extension _AppendKeyPath {
@_transparent
func unsafeSendable() -> _SendableAnyKeyPath
where Self == AnyKeyPath {
#if compiler(>=6)
unsafeBitCast(self, to: _SendableAnyKeyPath.self)
#else
self
#endif
}

@_transparent
func unsafeSendable<Root>() -> _SendablePartialKeyPath<Root>
where Self == PartialKeyPath<Root> {
#if compiler(>=6)
unsafeBitCast(self, to: _SendablePartialKeyPath<Root>.self)
#else
self
#endif
}

@_transparent
func unsafeSendable<Root, Value>() -> _SendableKeyPath<Root, Value>
where Self == KeyPath<Root, Value> {
#if compiler(>=6)
unsafeBitCast(self, to: _SendableKeyPath<Root, Value>.self)
#else
self
#endif
}

@_transparent
func unsafeSendable<Root, Value>() -> _SendableWritableKeyPath<Root, Value>
where Self == WritableKeyPath<Root, Value> {
#if compiler(>=6)
unsafeBitCast(self, to: _SendableWritableKeyPath<Root, Value>.self)
#else
self
#endif
}

@_transparent
func unsafeSendable<Root, Value>() -> _SendableReferenceWritableKeyPath<Root, Value>
where Self == ReferenceWritableKeyPath<Root, Value> {
#if compiler(>=6)
unsafeBitCast(self, to: _SendableReferenceWritableKeyPath<Root, Value>.self)
#else
self
#endif
}

@_transparent
func unsafeSendable<Root, Value>() -> _SendableCaseKeyPath<Root, Value>
where Self == CaseKeyPath<Root, Value> {
#if compiler(>=6)
unsafeBitCast(self, to: _SendableCaseKeyPath<Root, Value>.self)
#else
self
#endif
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -159,12 +159,12 @@ extension BindableAction where State: ObservableState {

extension Store where State: ObservableState, Action: BindableAction, Action.State == State {
public subscript<Value: Equatable & Sendable>(
dynamicMember keyPath: _SendableWritableKeyPath<State, Value>
dynamicMember keyPath: WritableKeyPath<State, Value>
) -> Value {
get { self.state[keyPath: keyPath] }
set {
BindingLocal.$isActive.withValue(true) {
self.send(.set(keyPath, newValue, isInvalidated: _isInvalidated))
self.send(.set(keyPath.unsafeSendable(), newValue, isInvalidated: _isInvalidated))
}
}
}
Expand Down Expand Up @@ -195,12 +195,12 @@ where
Action.ViewAction.State == State
{
public subscript<Value: Equatable & Sendable>(
dynamicMember keyPath: _SendableWritableKeyPath<State, Value>
dynamicMember keyPath: WritableKeyPath<State, Value>
) -> Value {
get { self.state[keyPath: keyPath] }
set {
BindingLocal.$isActive.withValue(true) {
self.send(.view(.set(keyPath, newValue, isInvalidated: _isInvalidated)))
self.send(.view(.set(keyPath.unsafeSendable(), newValue, isInvalidated: _isInvalidated)))
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -293,10 +293,11 @@ extension PresentationAction: CasePathable {
}

public subscript<AppendedAction>(
dynamicMember keyPath: _SendableCaseKeyPath<Action, AppendedAction>
dynamicMember keyPath: CaseKeyPath<Action, AppendedAction>
) -> AnyCasePath<PresentationAction, AppendedAction>
where Action: CasePathable {
AnyCasePath<PresentationAction, AppendedAction>(
let keyPath = keyPath.unsafeSendable()
return AnyCasePath<PresentationAction, AppendedAction>(
embed: { .presented(keyPath($0)) },
extract: {
guard case let .presented(action) = $0 else { return nil }
Expand All @@ -307,10 +308,11 @@ extension PresentationAction: CasePathable {

@_disfavoredOverload
public subscript<AppendedAction>(
dynamicMember keyPath: _SendableCaseKeyPath<Action, AppendedAction>
dynamicMember keyPath: CaseKeyPath<Action, AppendedAction>
) -> AnyCasePath<PresentationAction, PresentationAction<AppendedAction>>
where Action: CasePathable {
AnyCasePath<PresentationAction, PresentationAction<AppendedAction>>(
let keyPath = keyPath.unsafeSendable()
return AnyCasePath<PresentationAction, PresentationAction<AppendedAction>>(
embed: {
switch $0 {
case .dismiss:
Expand Down
19 changes: 7 additions & 12 deletions Sources/ComposableArchitecture/SharedState/Shared.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
@propertyWrapper
public struct Shared<Value: Sendable>: Sendable {
private let reference: any Reference
private let keyPath: _SendableAnyKeyPath

Check warning on line 17 in Sources/ComposableArchitecture/SharedState/Shared.swift

View workflow job for this annotation

GitHub Actions / xcodebuild (MACOS, 15.2)

stored property 'keyPath' of 'Sendable'-conforming generic struct 'Shared' has non-sendable type '_SendableAnyKeyPath' (aka 'AnyKeyPath')

Check warning on line 17 in Sources/ComposableArchitecture/SharedState/Shared.swift

View workflow job for this annotation

GitHub Actions / xcodebuild (MACOS, 15.2)

stored property 'keyPath' of 'Sendable'-conforming generic struct 'Shared' has non-sendable type '_SendableAnyKeyPath' (aka 'AnyKeyPath')

Check warning on line 17 in Sources/ComposableArchitecture/SharedState/Shared.swift

View workflow job for this annotation

GitHub Actions / xcodebuild (IOS, 15.2)

stored property 'keyPath' of 'Sendable'-conforming generic struct 'Shared' has non-sendable type '_SendableAnyKeyPath' (aka 'AnyKeyPath')

Check warning on line 17 in Sources/ComposableArchitecture/SharedState/Shared.swift

View workflow job for this annotation

GitHub Actions / xcodebuild (IOS, 15.2)

stored property 'keyPath' of 'Sendable'-conforming generic struct 'Shared' has non-sendable type '_SendableAnyKeyPath' (aka 'AnyKeyPath')

Check warning on line 17 in Sources/ComposableArchitecture/SharedState/Shared.swift

View workflow job for this annotation

GitHub Actions / xcodebuild (test, MAC_CATALYST, 15.4)

stored property 'keyPath' of 'Sendable'-conforming generic struct 'Shared' has non-sendable type '_SendableAnyKeyPath' (aka 'AnyKeyPath')

Check warning on line 17 in Sources/ComposableArchitecture/SharedState/Shared.swift

View workflow job for this annotation

GitHub Actions / xcodebuild (test, MAC_CATALYST, 15.4)

stored property 'keyPath' of 'Sendable'-conforming generic struct 'Shared' has non-sendable type '_SendableAnyKeyPath' (aka 'AnyKeyPath')

Check warning on line 17 in Sources/ComposableArchitecture/SharedState/Shared.swift

View workflow job for this annotation

GitHub Actions / xcodebuild (test, MAC_CATALYST, 15.4)

stored property 'keyPath' of 'Sendable'-conforming generic struct 'Shared' has non-sendable type '_SendableAnyKeyPath' (aka 'AnyKeyPath')

Check warning on line 17 in Sources/ComposableArchitecture/SharedState/Shared.swift

View workflow job for this annotation

GitHub Actions / xcodebuild (test, MAC_CATALYST, 15.4)

stored property 'keyPath' of 'Sendable'-conforming generic struct 'Shared' has non-sendable type '_SendableAnyKeyPath' (aka 'AnyKeyPath')

Check warning on line 17 in Sources/ComposableArchitecture/SharedState/Shared.swift

View workflow job for this annotation

GitHub Actions / xcodebuild (test, IOS, 15.4)

stored property 'keyPath' of 'Sendable'-conforming generic struct 'Shared' has non-sendable type '_SendableAnyKeyPath' (aka 'AnyKeyPath')

Check warning on line 17 in Sources/ComposableArchitecture/SharedState/Shared.swift

View workflow job for this annotation

GitHub Actions / xcodebuild (test, IOS, 15.4)

stored property 'keyPath' of 'Sendable'-conforming generic struct 'Shared' has non-sendable type '_SendableAnyKeyPath' (aka 'AnyKeyPath')

Check warning on line 17 in Sources/ComposableArchitecture/SharedState/Shared.swift

View workflow job for this annotation

GitHub Actions / xcodebuild (test, IOS, 15.4)

stored property 'keyPath' of 'Sendable'-conforming generic struct 'Shared' has non-sendable type '_SendableAnyKeyPath' (aka 'AnyKeyPath')

Check warning on line 17 in Sources/ComposableArchitecture/SharedState/Shared.swift

View workflow job for this annotation

GitHub Actions / xcodebuild (test, IOS, 15.4)

stored property 'keyPath' of 'Sendable'-conforming generic struct 'Shared' has non-sendable type '_SendableAnyKeyPath' (aka 'AnyKeyPath')

Check warning on line 17 in Sources/ComposableArchitecture/SharedState/Shared.swift

View workflow job for this annotation

GitHub Actions / xcodebuild (test, TVOS, 15.4)

stored property 'keyPath' of 'Sendable'-conforming generic struct 'Shared' has non-sendable type '_SendableAnyKeyPath' (aka 'AnyKeyPath')

Check warning on line 17 in Sources/ComposableArchitecture/SharedState/Shared.swift

View workflow job for this annotation

GitHub Actions / xcodebuild (test, TVOS, 15.4)

stored property 'keyPath' of 'Sendable'-conforming generic struct 'Shared' has non-sendable type '_SendableAnyKeyPath' (aka 'AnyKeyPath')

Check warning on line 17 in Sources/ComposableArchitecture/SharedState/Shared.swift

View workflow job for this annotation

GitHub Actions / xcodebuild (test, TVOS, 15.4)

stored property 'keyPath' of 'Sendable'-conforming generic struct 'Shared' has non-sendable type '_SendableAnyKeyPath' (aka 'AnyKeyPath')

Check warning on line 17 in Sources/ComposableArchitecture/SharedState/Shared.swift

View workflow job for this annotation

GitHub Actions / xcodebuild (test, TVOS, 15.4)

stored property 'keyPath' of 'Sendable'-conforming generic struct 'Shared' has non-sendable type '_SendableAnyKeyPath' (aka 'AnyKeyPath')

Check warning on line 17 in Sources/ComposableArchitecture/SharedState/Shared.swift

View workflow job for this annotation

GitHub Actions / xcodebuild (test, MACOS, 15.4)

stored property 'keyPath' of 'Sendable'-conforming generic struct 'Shared' has non-sendable type '_SendableAnyKeyPath' (aka 'AnyKeyPath')

Check warning on line 17 in Sources/ComposableArchitecture/SharedState/Shared.swift

View workflow job for this annotation

GitHub Actions / xcodebuild (test, MACOS, 15.4)

stored property 'keyPath' of 'Sendable'-conforming generic struct 'Shared' has non-sendable type '_SendableAnyKeyPath' (aka 'AnyKeyPath')

Check warning on line 17 in Sources/ComposableArchitecture/SharedState/Shared.swift

View workflow job for this annotation

GitHub Actions / xcodebuild (test, MACOS, 15.4)

stored property 'keyPath' of 'Sendable'-conforming generic struct 'Shared' has non-sendable type '_SendableAnyKeyPath' (aka 'AnyKeyPath')

Check warning on line 17 in Sources/ComposableArchitecture/SharedState/Shared.swift

View workflow job for this annotation

GitHub Actions / xcodebuild (test, MACOS, 15.4)

stored property 'keyPath' of 'Sendable'-conforming generic struct 'Shared' has non-sendable type '_SendableAnyKeyPath' (aka 'AnyKeyPath')

Check warning on line 17 in Sources/ComposableArchitecture/SharedState/Shared.swift

View workflow job for this annotation

GitHub Actions / xcodebuild (test, WATCHOS, 15.4)

stored property 'keyPath' of 'Sendable'-conforming generic struct 'Shared' has non-sendable type '_SendableAnyKeyPath' (aka 'AnyKeyPath')

Check warning on line 17 in Sources/ComposableArchitecture/SharedState/Shared.swift

View workflow job for this annotation

GitHub Actions / xcodebuild (test, WATCHOS, 15.4)

stored property 'keyPath' of 'Sendable'-conforming generic struct 'Shared' has non-sendable type '_SendableAnyKeyPath' (aka 'AnyKeyPath')

Check warning on line 17 in Sources/ComposableArchitecture/SharedState/Shared.swift

View workflow job for this annotation

GitHub Actions / xcodebuild (test, WATCHOS, 15.4)

stored property 'keyPath' of 'Sendable'-conforming generic struct 'Shared' has non-sendable type '_SendableAnyKeyPath' (aka 'AnyKeyPath')

Check warning on line 17 in Sources/ComposableArchitecture/SharedState/Shared.swift

View workflow job for this annotation

GitHub Actions / xcodebuild (test, WATCHOS, 15.4)

stored property 'keyPath' of 'Sendable'-conforming generic struct 'Shared' has non-sendable type '_SendableAnyKeyPath' (aka 'AnyKeyPath')

Check warning on line 17 in Sources/ComposableArchitecture/SharedState/Shared.swift

View workflow job for this annotation

GitHub Actions / xcodebuild (test, WATCHOS, 15.4)

stored property 'keyPath' of 'Sendable'-conforming generic struct 'Shared' has non-sendable type '_SendableAnyKeyPath' (aka 'AnyKeyPath')

Check warning on line 17 in Sources/ComposableArchitecture/SharedState/Shared.swift

View workflow job for this annotation

GitHub Actions / xcodebuild (test, VISIONOS, 15.4)

stored property 'keyPath' of 'Sendable'-conforming generic struct 'Shared' has non-sendable type '_SendableAnyKeyPath' (aka 'AnyKeyPath')

Check warning on line 17 in Sources/ComposableArchitecture/SharedState/Shared.swift

View workflow job for this annotation

GitHub Actions / xcodebuild (test, VISIONOS, 15.4)

stored property 'keyPath' of 'Sendable'-conforming generic struct 'Shared' has non-sendable type '_SendableAnyKeyPath' (aka 'AnyKeyPath')

Check warning on line 17 in Sources/ComposableArchitecture/SharedState/Shared.swift

View workflow job for this annotation

GitHub Actions / xcodebuild (test, VISIONOS, 15.4)

stored property 'keyPath' of 'Sendable'-conforming generic struct 'Shared' has non-sendable type '_SendableAnyKeyPath' (aka 'AnyKeyPath')

Check warning on line 17 in Sources/ComposableArchitecture/SharedState/Shared.swift

View workflow job for this annotation

GitHub Actions / xcodebuild (test, VISIONOS, 15.4)

stored property 'keyPath' of 'Sendable'-conforming generic struct 'Shared' has non-sendable type '_SendableAnyKeyPath' (aka 'AnyKeyPath')

init(reference: any Reference, keyPath: _SendableAnyKeyPath) {
self.reference = reference
Expand Down Expand Up @@ -64,10 +64,9 @@
reference: base.reference,
// NB: Can get rid of bitcast when this is fixed:
// https://github.com/swiftlang/swift/issues/75531
keyPath: sendableKeyPath(
(base.keyPath as AnyKeyPath)
.appending(path: \Value?.[default: DefaultSubscript(initialValue)])!
)
keyPath: (base.keyPath as AnyKeyPath)
.appending(path: \Value?.[default: DefaultSubscript(initialValue)])!
.unsafeSendable()
)
}

Expand Down Expand Up @@ -179,9 +178,9 @@
reference: self.reference,
// NB: Can get rid of bitcast when this is fixed:
// https://github.com/swiftlang/swift/issues/75531
keyPath: sendableKeyPath(
(self.keyPath as AnyKeyPath).appending(path: keyPath)!
)
keyPath: (self.keyPath as AnyKeyPath)
.appending(path: keyPath)!
.unsafeSendable()
)
}

Expand Down Expand Up @@ -459,11 +458,7 @@
) -> SharedReader<Member> {
SharedReader<Member>(
reference: self.reference,
// NB: Can get rid of bitcast when this is fixed:
// https://github.com/swiftlang/swift/issues/75531
keyPath: sendableKeyPath(
(self.keyPath as AnyKeyPath).appending(path: keyPath)!
)
keyPath: (self.keyPath as AnyKeyPath).appending(path: keyPath)!.unsafeSendable()
)
}

Expand Down
20 changes: 12 additions & 8 deletions Sources/ComposableArchitecture/SwiftUI/Binding.swift
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@
///
/// Read <doc:Bindings> for more information.
public struct BindingAction<Root>: CasePathable, Equatable, Sendable {
public let keyPath: _SendablePartialKeyPath<Root>

Check warning on line 147 in Sources/ComposableArchitecture/SwiftUI/Binding.swift

View workflow job for this annotation

GitHub Actions / xcodebuild (MACOS, 15.2)

stored property 'keyPath' of 'Sendable'-conforming generic struct 'BindingAction' has non-sendable type '_SendablePartialKeyPath<Root>' (aka 'PartialKeyPath<Root>')

Check warning on line 147 in Sources/ComposableArchitecture/SwiftUI/Binding.swift

View workflow job for this annotation

GitHub Actions / xcodebuild (MACOS, 15.2)

stored property 'keyPath' of 'Sendable'-conforming generic struct 'BindingAction' has non-sendable type '_SendablePartialKeyPath<Root>' (aka 'PartialKeyPath<Root>')

Check warning on line 147 in Sources/ComposableArchitecture/SwiftUI/Binding.swift

View workflow job for this annotation

GitHub Actions / xcodebuild (IOS, 15.2)

stored property 'keyPath' of 'Sendable'-conforming generic struct 'BindingAction' has non-sendable type '_SendablePartialKeyPath<Root>' (aka 'PartialKeyPath<Root>')

Check warning on line 147 in Sources/ComposableArchitecture/SwiftUI/Binding.swift

View workflow job for this annotation

GitHub Actions / xcodebuild (IOS, 15.2)

stored property 'keyPath' of 'Sendable'-conforming generic struct 'BindingAction' has non-sendable type '_SendablePartialKeyPath<Root>' (aka 'PartialKeyPath<Root>')

Check warning on line 147 in Sources/ComposableArchitecture/SwiftUI/Binding.swift

View workflow job for this annotation

GitHub Actions / xcodebuild (test, MAC_CATALYST, 15.4)

stored property 'keyPath' of 'Sendable'-conforming generic struct 'BindingAction' has non-sendable type '_SendablePartialKeyPath<Root>' (aka 'PartialKeyPath<Root>')

Check warning on line 147 in Sources/ComposableArchitecture/SwiftUI/Binding.swift

View workflow job for this annotation

GitHub Actions / xcodebuild (test, MAC_CATALYST, 15.4)

stored property 'keyPath' of 'Sendable'-conforming generic struct 'BindingAction' has non-sendable type '_SendablePartialKeyPath<Root>' (aka 'PartialKeyPath<Root>')

Check warning on line 147 in Sources/ComposableArchitecture/SwiftUI/Binding.swift

View workflow job for this annotation

GitHub Actions / xcodebuild (test, MAC_CATALYST, 15.4)

stored property 'keyPath' of 'Sendable'-conforming generic struct 'BindingAction' has non-sendable type '_SendablePartialKeyPath<Root>' (aka 'PartialKeyPath<Root>')

Check warning on line 147 in Sources/ComposableArchitecture/SwiftUI/Binding.swift

View workflow job for this annotation

GitHub Actions / xcodebuild (test, MAC_CATALYST, 15.4)

stored property 'keyPath' of 'Sendable'-conforming generic struct 'BindingAction' has non-sendable type '_SendablePartialKeyPath<Root>' (aka 'PartialKeyPath<Root>')

Check warning on line 147 in Sources/ComposableArchitecture/SwiftUI/Binding.swift

View workflow job for this annotation

GitHub Actions / xcodebuild (test, IOS, 15.4)

stored property 'keyPath' of 'Sendable'-conforming generic struct 'BindingAction' has non-sendable type '_SendablePartialKeyPath<Root>' (aka 'PartialKeyPath<Root>')

Check warning on line 147 in Sources/ComposableArchitecture/SwiftUI/Binding.swift

View workflow job for this annotation

GitHub Actions / xcodebuild (test, IOS, 15.4)

stored property 'keyPath' of 'Sendable'-conforming generic struct 'BindingAction' has non-sendable type '_SendablePartialKeyPath<Root>' (aka 'PartialKeyPath<Root>')

Check warning on line 147 in Sources/ComposableArchitecture/SwiftUI/Binding.swift

View workflow job for this annotation

GitHub Actions / xcodebuild (test, IOS, 15.4)

stored property 'keyPath' of 'Sendable'-conforming generic struct 'BindingAction' has non-sendable type '_SendablePartialKeyPath<Root>' (aka 'PartialKeyPath<Root>')

Check warning on line 147 in Sources/ComposableArchitecture/SwiftUI/Binding.swift

View workflow job for this annotation

GitHub Actions / xcodebuild (test, IOS, 15.4)

stored property 'keyPath' of 'Sendable'-conforming generic struct 'BindingAction' has non-sendable type '_SendablePartialKeyPath<Root>' (aka 'PartialKeyPath<Root>')

Check warning on line 147 in Sources/ComposableArchitecture/SwiftUI/Binding.swift

View workflow job for this annotation

GitHub Actions / xcodebuild (test, TVOS, 15.4)

stored property 'keyPath' of 'Sendable'-conforming generic struct 'BindingAction' has non-sendable type '_SendablePartialKeyPath<Root>' (aka 'PartialKeyPath<Root>')

Check warning on line 147 in Sources/ComposableArchitecture/SwiftUI/Binding.swift

View workflow job for this annotation

GitHub Actions / xcodebuild (test, TVOS, 15.4)

stored property 'keyPath' of 'Sendable'-conforming generic struct 'BindingAction' has non-sendable type '_SendablePartialKeyPath<Root>' (aka 'PartialKeyPath<Root>')

Check warning on line 147 in Sources/ComposableArchitecture/SwiftUI/Binding.swift

View workflow job for this annotation

GitHub Actions / xcodebuild (test, TVOS, 15.4)

stored property 'keyPath' of 'Sendable'-conforming generic struct 'BindingAction' has non-sendable type '_SendablePartialKeyPath<Root>' (aka 'PartialKeyPath<Root>')

Check warning on line 147 in Sources/ComposableArchitecture/SwiftUI/Binding.swift

View workflow job for this annotation

GitHub Actions / xcodebuild (test, TVOS, 15.4)

stored property 'keyPath' of 'Sendable'-conforming generic struct 'BindingAction' has non-sendable type '_SendablePartialKeyPath<Root>' (aka 'PartialKeyPath<Root>')

Check warning on line 147 in Sources/ComposableArchitecture/SwiftUI/Binding.swift

View workflow job for this annotation

GitHub Actions / xcodebuild (test, MACOS, 15.4)

stored property 'keyPath' of 'Sendable'-conforming generic struct 'BindingAction' has non-sendable type '_SendablePartialKeyPath<Root>' (aka 'PartialKeyPath<Root>')

Check warning on line 147 in Sources/ComposableArchitecture/SwiftUI/Binding.swift

View workflow job for this annotation

GitHub Actions / xcodebuild (test, MACOS, 15.4)

stored property 'keyPath' of 'Sendable'-conforming generic struct 'BindingAction' has non-sendable type '_SendablePartialKeyPath<Root>' (aka 'PartialKeyPath<Root>')

Check warning on line 147 in Sources/ComposableArchitecture/SwiftUI/Binding.swift

View workflow job for this annotation

GitHub Actions / xcodebuild (test, MACOS, 15.4)

stored property 'keyPath' of 'Sendable'-conforming generic struct 'BindingAction' has non-sendable type '_SendablePartialKeyPath<Root>' (aka 'PartialKeyPath<Root>')

Check warning on line 147 in Sources/ComposableArchitecture/SwiftUI/Binding.swift

View workflow job for this annotation

GitHub Actions / xcodebuild (test, MACOS, 15.4)

stored property 'keyPath' of 'Sendable'-conforming generic struct 'BindingAction' has non-sendable type '_SendablePartialKeyPath<Root>' (aka 'PartialKeyPath<Root>')

Check warning on line 147 in Sources/ComposableArchitecture/SwiftUI/Binding.swift

View workflow job for this annotation

GitHub Actions / xcodebuild (test, WATCHOS, 15.4)

stored property 'keyPath' of 'Sendable'-conforming generic struct 'BindingAction' has non-sendable type '_SendablePartialKeyPath<Root>' (aka 'PartialKeyPath<Root>')

Check warning on line 147 in Sources/ComposableArchitecture/SwiftUI/Binding.swift

View workflow job for this annotation

GitHub Actions / xcodebuild (test, WATCHOS, 15.4)

stored property 'keyPath' of 'Sendable'-conforming generic struct 'BindingAction' has non-sendable type '_SendablePartialKeyPath<Root>' (aka 'PartialKeyPath<Root>')

Check warning on line 147 in Sources/ComposableArchitecture/SwiftUI/Binding.swift

View workflow job for this annotation

GitHub Actions / xcodebuild (test, WATCHOS, 15.4)

stored property 'keyPath' of 'Sendable'-conforming generic struct 'BindingAction' has non-sendable type '_SendablePartialKeyPath<Root>' (aka 'PartialKeyPath<Root>')

Check warning on line 147 in Sources/ComposableArchitecture/SwiftUI/Binding.swift

View workflow job for this annotation

GitHub Actions / xcodebuild (test, WATCHOS, 15.4)

stored property 'keyPath' of 'Sendable'-conforming generic struct 'BindingAction' has non-sendable type '_SendablePartialKeyPath<Root>' (aka 'PartialKeyPath<Root>')

Check warning on line 147 in Sources/ComposableArchitecture/SwiftUI/Binding.swift

View workflow job for this annotation

GitHub Actions / xcodebuild (test, WATCHOS, 15.4)

stored property 'keyPath' of 'Sendable'-conforming generic struct 'BindingAction' has non-sendable type '_SendablePartialKeyPath<Root>' (aka 'PartialKeyPath<Root>')

Check warning on line 147 in Sources/ComposableArchitecture/SwiftUI/Binding.swift

View workflow job for this annotation

GitHub Actions / xcodebuild (test, VISIONOS, 15.4)

stored property 'keyPath' of 'Sendable'-conforming generic struct 'BindingAction' has non-sendable type '_SendablePartialKeyPath<Root>' (aka 'PartialKeyPath<Root>')

Check warning on line 147 in Sources/ComposableArchitecture/SwiftUI/Binding.swift

View workflow job for this annotation

GitHub Actions / xcodebuild (test, VISIONOS, 15.4)

stored property 'keyPath' of 'Sendable'-conforming generic struct 'BindingAction' has non-sendable type '_SendablePartialKeyPath<Root>' (aka 'PartialKeyPath<Root>')

Check warning on line 147 in Sources/ComposableArchitecture/SwiftUI/Binding.swift

View workflow job for this annotation

GitHub Actions / xcodebuild (test, VISIONOS, 15.4)

stored property 'keyPath' of 'Sendable'-conforming generic struct 'BindingAction' has non-sendable type '_SendablePartialKeyPath<Root>' (aka 'PartialKeyPath<Root>')

Check warning on line 147 in Sources/ComposableArchitecture/SwiftUI/Binding.swift

View workflow job for this annotation

GitHub Actions / xcodebuild (test, VISIONOS, 15.4)

stored property 'keyPath' of 'Sendable'-conforming generic struct 'BindingAction' has non-sendable type '_SendablePartialKeyPath<Root>' (aka 'PartialKeyPath<Root>')

@usableFromInline
let set: @Sendable (inout Root) -> Void
Expand Down Expand Up @@ -174,18 +174,20 @@
@dynamicMemberLookup
public struct AllCasePaths {
public subscript<Value: Equatable & Sendable>(
dynamicMember keyPath: _SendableWritableKeyPath<Root, Value>
dynamicMember keyPath: WritableKeyPath<Root, Value>
) -> AnyCasePath<BindingAction, Value> where Root: ObservableState {
AnyCasePath(
let keyPath = keyPath.unsafeSendable()
return AnyCasePath(
embed: { .set(keyPath, $0) },
extract: { $0.keyPath == keyPath ? $0.value as? Value : nil }
)
}

public subscript<Value: Equatable & Sendable>(
dynamicMember keyPath: _SendableWritableKeyPath<Root, BindingState<Value>>
dynamicMember keyPath: WritableKeyPath<Root, BindingState<Value>>
) -> AnyCasePath<BindingAction, Value> {
AnyCasePath(
let keyPath = keyPath.unsafeSendable()
return AnyCasePath(
embed: { .set(keyPath, $0) },
extract: { $0.keyPath == keyPath ? $0.value as? Value : nil }
)
Expand Down Expand Up @@ -299,9 +301,10 @@

extension ViewStore where ViewAction: BindableAction, ViewAction.State == ViewState {
public subscript<Value: Equatable & Sendable>(
dynamicMember keyPath: _SendableWritableKeyPath<ViewState, BindingState<Value>>
dynamicMember keyPath: WritableKeyPath<ViewState, BindingState<Value>>
) -> Binding<Value> {
self.binding(
let keyPath = keyPath.unsafeSendable()
return self.binding(
get: { $0[keyPath: keyPath].wrappedValue },
send: { value in
#if DEBUG
Expand Down Expand Up @@ -454,9 +457,10 @@
}

public subscript<Value: Equatable & Sendable>(
dynamicMember keyPath: _SendableWritableKeyPath<State, BindingState<Value>>
dynamicMember keyPath: WritableKeyPath<State, BindingState<Value>>
) -> BindingViewState<Value> {
BindingViewState(
let keyPath = keyPath.unsafeSendable()
return BindingViewState(
binding: ViewStore(self.store, observe: { $0[keyPath: keyPath].wrappedValue })
.binding(
send: { value in
Expand Down
Loading