One addition Iād like to see is an ability to optionally specify the discriminator, as an integral type, or - more interestingly - another enum. Using an alternative syntax:
type TwoTypes = enum(u8) Foo | Bar; // or "enum(Foo | Bar; u8)", or ...
In the above, the discriminator is of size u8, values assigned automatically. Going further:
type FourTypes = enum(TwoTypes) Foo | Bar | Baz | Quz;
type ThreeTypes = enum(FourTypes) Bar | Baz | Quz;
Here, FourTypes expands on TwoTypes discriminator and uses the same discriminator values for the same types TwoTypes does. Hence, TwoTypes can seamlessly be assigned or referred-to (non-mutably) wherever FourTypes is expected.
Conversely, ThreeTypes is a subset of FourTypes and can also be used wherever the latter is expected.
However:
type MixedTypes = enum(ThreeTypes) Bar | Baz | Other;
This re-uses the discriminator size and values for Bar and Baz, but both omits Quz and adds Other. IOW, while this would compile fine, MixedTypes cannot be used in the place of ThreeTypes, nor vice versa.