Skip to content

Commit

Permalink
Don't pass embed functions directly to AnyCasePath.init (#3167)
Browse files Browse the repository at this point in the history
`AnyCasePath` closures will be required to be `@Sendable` for Swift 6
data race checking, but `Enum.case` functions are not `@Sendable`
implicitly. As such we cannot pass `Enum.case` directly to functions
that expect sendable closures. Instead, we must explicitly write:

```swift
{ .case($0) }
```
  • Loading branch information
stephencelis committed Jun 14, 2024
1 parent 3bc77de commit fd9ef56
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public enum IdentifiedAction<ID: Hashable, Action>: CasePathable {
public struct AllCasePaths {
public var element: AnyCasePath<IdentifiedAction, (id: ID, action: Action)> {
AnyCasePath(
embed: IdentifiedAction.element,
embed: { .element(id: $0, action: $1) },
extract: {
guard case let .element(id, action) = $0 else { return nil }
return (id, action)
Expand Down Expand Up @@ -169,8 +169,8 @@ extension Reducer {
parent: self,
toElementsState: toElementsState,
toElementAction: .init(
embed: toElementAction.embed,
extract: toElementAction.extract
embed: { toElementAction.embed($0) },
extract: { toElementAction.extract(from: $0) }
),
element: element(),
fileID: fileID,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ extension PresentationAction: CasePathable {

public var presented: AnyCasePath<PresentationAction, Action> {
AnyCasePath(
embed: PresentationAction.presented,
embed: { .presented($0) },
extract: {
guard case let .presented(value) = $0 else { return nil }
return value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ public enum StackAction<State, Action>: CasePathable {
public struct AllCasePaths {
public var element: AnyCasePath<StackAction, (id: StackElementID, action: Action)> {
AnyCasePath(
embed: StackAction.element,
embed: { .element(id: $0, action: $1) },
extract: {
guard case let .element(id, action) = $0 else { return nil }
return (id: id, action: action)
Expand All @@ -252,7 +252,7 @@ public enum StackAction<State, Action>: CasePathable {

public var popFrom: AnyCasePath<StackAction, StackElementID> {
AnyCasePath(
embed: StackAction.popFrom,
embed: { .popFrom(id: $0) },
extract: {
guard case let .popFrom(id) = $0 else { return nil }
return id
Expand All @@ -262,7 +262,7 @@ public enum StackAction<State, Action>: CasePathable {

public var push: AnyCasePath<StackAction, (id: StackElementID, state: State)> {
AnyCasePath(
embed: StackAction.push,
embed: { .push(id: $0, state: $1) },
extract: {
guard case let .push(id, state) = $0 else { return nil }
return (id: id, state: state)
Expand Down
2 changes: 1 addition & 1 deletion Sources/ComposableArchitecture/SwiftUI/Binding.swift
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ public protocol BindableAction {

extension BindableAction {
public var binding: BindingAction<State>? {
AnyCasePath(unsafe: Self.binding).extract(from: self)
AnyCasePath(unsafe: { .binding($0) }).extract(from: self)
}
}

Expand Down

0 comments on commit fd9ef56

Please sign in to comment.