Nested enum reducer error: cannot be constructed because it has no accessible initializers
Closed this issue · 3 comments
Description
The case is pretty simple. The error occurs if you have nested macro-generated enum reducer (e.g. Feature1) in another macro-generated enum reducer (.e.g. Feature2).
Looks that issue occurs since Reducer macro doesn't take into account that macro-generated enum Reducers don't have inits.
Checklist
- I have determined whether this bug is also reproducible in a vanilla SwiftUI project.
- If possible, I've reproduced the issue using the
main
branch of this package. - This issue hasn't been addressed in an existing GitHub issue or discussion.
Expected behavior
No error occurs.
Actual behavior
Compiler reports an error: 'Type' cannot be constructed because it has no accessible initializers
Steps to reproduce
See the code below.
@Reducer(state: .equatable)
enum Feature1 {
case a
case b
}
@Reducer(state: .equatable)
enum Feature2 {
case feature1(Feature1)
}
The Composable Architecture version information
1.10.2
Destination operating system
No response
Xcode version information
Version 15.3 (15E204a)
Swift Compiler version information
swift-driver version: 1.90.11.1 Apple Swift version 5.10 (swiftlang-5.10.0.13 clang-1500.3.9.4)
Target: arm64-apple-macosx14.0
@larryonoff This feature was added recently: #2814
The macro has no knowledge of what the type of reducer being fed to a case is, so outside the default, you must specify the exact reducer kind and how to construct it using a default argument:
@Reducer(state: .equatable)
enum Feature2 {
case feature1(Feature1.Body = Feature1.body)
}
Does this work for you?
@stephencelis thank you! it works like a charm!
Is it in the docs already?
@larryonoff I don't believe it's documented yet, but we'll PR some later today!