Skip to content

Commit

Permalink
Fix BindingAction's case key path for extraction (#2600)
Browse files Browse the repository at this point in the history
  • Loading branch information
stephencelis authored Nov 29, 2023
1 parent 6772c9d commit efba133
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Sources/ComposableArchitecture/SwiftUI/Binding.swift
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ public struct BindingAction<Root>: CasePathable, Equatable, @unchecked Sendable
) -> AnyCasePath<BindingAction, Value> {
AnyCasePath(
embed: { .set(keyPath, $0) },
extract: { $0.keyPath == keyPath ? $0.value as? Value : nil }
extract: { $0.keyPath == keyPath ? $0.value.base as? Value : nil }
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,4 +126,18 @@ final class BindingTests: BaseTCATestCase {
}
_ = AnyCasePath(unsafe: Foo.bar).extract(from: .bar(.buzz(true)))
}

struct TestMatching {
struct CounterState {
@BindingState var count = 0
}
@CasePathable
enum CounterAction: CasePathable {
case binding(BindingAction<CounterState>)
}
}
func testMatching() {
let action = TestMatching.CounterAction.binding(.set(\.$count, 42))
XCTAssertEqual(action[case: \.binding.$count], 42)
}
}

0 comments on commit efba133

Please sign in to comment.