> On Feb 11, 2017, at 2:25 AM, Adrian Zubarev via swift-evolution
> <[email protected]> wrote:
>
> // Allowed because `C` is open, and open allows sub-typing, conforming
> // and overriding to the client
> enum SubC : C {
> case cc
> }
There's a subtle mistake here. For a sum type, subtyping actually means
*removing* cases, not *adding* cases. (Or it can mean changing some of the
associated types into their subtypes, but that's a different story.)
To understand why, think about casting between `C` and `SubC`. Specifically,
imagine this upcast:
SubC.cc as C
What is this supposed to do? There is no `cc` case in `C`, so `SubC.cc` cannot
be represented as a `C`. That means `SubC` is not a subtype of `C`. In fact,
`SubC` would be a *supertype* of `C`—you would need to say `SubC.cc as? C`, but
you could always say `C.c as SubC`.
(The ultimate expression of this is that `Never`—which can be thought of as the
subtype of all types—is an empty enum.)
That's not to say that this is a feature we should add; rather, it's to say
that the concept of inheritance doesn't really make any sense for `enum`s.
Just something I noticed when I was reading this thread. I'll have more to say
on the main topic, hopefully soon.
--
Brent Royal-Gordon
Architechies
_______________________________________________
swift-evolution mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-evolution