Ok I think I realized what I’m concretely proposing. Consider the Result
type:
enum Result <Success, Failure> {
case success (Success)
case failure (Failure)
}
extension Result: Codable
where Success: Codable,
Failure: Codable { }
today, the above code does not allow me to do the following:
takesCodableValue(
Result<Int, Never>
.success(7)
)
Under the current proposal this would be made to work, because Never
will now conform to Codable
.
My proposal is that we consider making the function call work not by making Never
conform to Codable
but rather by changing the way in which the compiler interacts with Never
such that when it is considering whether or not Result<Int, Never>
deserves the conditional conformance to Codable
it arrives at the answer “yes” because the effect of Never
is to completely remove the failure
case from the enum, meaning that after substituting the concrete type parameters (Int, Never)
the compiler sees the enum:
enum Result: Codable {
case success (Int)
}
which of course we can easily synthesize the Codable
conformance for.
If I’m not mistaken, the error that I was suggesting that Result<Int, Never>
should throw when attempting to decode itself from the data {“failure”:{“errorCode”:1}}
is what would naturally fall out of my new proposal.
Maybe most importantly, this approach would also automatically yield things like Equatable
conformance for Result<Int, Never>
.
Actually, it would remove the need to ever conform (Ok maybe not this, I just had some new thoughts that I think mean I’m wrong here. I think this only applies to the handful of protocols for which the compiler synthesizes a memberwise conformance.)Never
to any protocol if all you need is for conditional conformance to work for your enum.
Lastly, I’ll say that to me this seems to better capture the real reason why Result<Int, Never>
is Codable
- it’s not really because Never
s are Codable
, it’s because there are no Never
s, which I think is exactly the thing provoking the ongoing debate about which error to throw.