Closed Jackstone92 closed 1 month ago
@Jackstone92 Thanks for taking the time to PR!
Unfortunately the @Shared
type cannot be conditionally hashable because it's reference-y, and that means its hash could change over time. We document this as a "gotcha" here: https://pointfreeco.github.io/swift-composable-architecture/main/documentation/composablearchitecture/sharingstate/#Hashability
One example problem is that if you used a Shared
value as a key in a dictionary, and its hash changed after insertion, the dictionary would be in an invalid state, which I believe would lead to a precondition/crash.
Generally reference-y things are hashable by their object identifier, but we can't do that here, either, because the equatable conformance would then be wrong. So we're kinda stuck here.
Please let us know the scenario you ran into this problem, though! Maybe there are other solutions to it.
Ah yeah that is a "gotcha"! Thanks, will close this and keep digging!
Here's a small PR that adds conditional
Hashable
conformance toShared
in a similar fashion toBindingState
.