Happy to see a pitch in this area! I think this is a good start in the direction of having something in place for enum
s which has been missing for a long time. I'm wondering about a few cases here which are not explicitly discussed in the pitch:
-
What about
enum
cases without associated values? Are those still encoded as keyed containers, or single values? For instance,.load
inenum Command: Codable { case load case store(key: String, value: Int) }
-
What about
enum
cases that share a name? For instance, both cases ofenum Foo { case bar(String, id: Int) case bar(String, value: Double) }
could end up with the same encoded representation (
{"bar": ["abc", 123]}
could match either). Would the synthesized initializer try cases in order, or how would that work? -
It would be nice to see some Alternatives Considered/Future Directions with some discussion about other approaches. For instance, from a lot of discussion in Automatic Codable conformance for enums with associated values that themselves conform to Codable and similar threads, we know that different folks have differing opinions on what they would expect to be a default implementation based on their needs.
- As part of that, I'd be curious to see some discussion about potentials for customization of synthesis (whether planned/declared to be an anti-goal/etc.), primarily, strategies for using a discriminator vs. not