Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes around optionals and partial case key paths (#147)
We recently added code that can flatten optionals in a couple of ways, but because these methods weren't disfavored, they take precedent and can produce case key paths incapable of expressing what you want, like the ability to embed a optional in an case that contains an optional: ```swift @CasePathable enum Foo { case bar(Int?) } let kp = \Foo.Cases.bar // CaseKeyPath<Foo, Int>, not <Foo, Int?> kp(nil) // 'nil' is not compatible with expected argument type 'Int' ``` This PR disfavors these overloads to allow you to flatten optionals contextually, but by default will leave them alone. It also fixes a bug in `PartialCaseKeyPath.callAsFunction` that would prevent non-optionals from being promoted to optionals in cases that expect them: ```swift let kp: PartialCaseKeyPath<Foo> = \.bar kp(42) // nil ``` Finally, this PR fixes a bug in which `PartialCaseKeyPath.callAsFunction` was technically available on `CaseKeyPath`, which meant you could call it with any value.
- Loading branch information