swift-composable-architecture
swift-composable-architecture copied to clipboard
Key path cannot refer to static member '....' Error
Description
When I tried to leverage all new features of version 1.7, I faced an error with observing case the path for the nested state. Accessing the case path scoping store shows: Key path cannot refer to static member '....'
.
Here is example implemented in both versions:
@Reducer
struct StructA {
@ObservableState
struct State {
var structB: StructB
}
enum Action {
case contentA(ContentAReducer.Action)
}
}
struct StructB {
var content: Content
@ObservableState
public enum Content {
case contentA(ContentAReducer.State)
}
}
@Reducer
struct ContentAReducer {
@ObservableState
struct State {
var text: String
}
enum Action {}
}
struct ContentAView: View {
var store: StoreOf<ContentAReducer>
var body: some View {
Text(store.text)
}
}
struct StructAView: View {
@Binding var store: Store<StructB.Content, StructA.Action>
var body: some View {
// Old version works, but soft-deprecated
SwitchStore(self.store) { content in
switch content {
case .contentA:
CaseLet(/StructB.Content.contentA, action: StructA.Action.contentA) { store in
ContentAView(store: store)
}
}
}
// New version prints an error:
// Key path cannot refer to static member 'contentA'
switch store.state {
case .contentA:
if let store = store.scope(state: \.contentA, action: \.contentA) {
ContentAView(store: store)
}
}
}
}
Checklist
- [ ] I have determined whether this bug is also reproducible in a vanilla SwiftUI project.
- [X] If possible, I've reproduced the issue using the
main
branch of this package. - [X] This issue hasn't been addressed in an existing GitHub issue or discussion.
Expected behavior
No response
Actual behavior
No response
Steps to reproduce
No response
The Composable Architecture version information
1.10.2
Destination operating system
iOS15
Xcode version information
Version 15.2 (15C500b)
Swift Compiler version information
swift-driver version: 1.87.3 Apple Swift version 5.9.2 (swiftlang-5.9.2.2.56 clang-1500.1.0.2.5)
Target: x86_64-apple-macosx14.0