draft proposal for Sum Types for D

Walter Bright newshound2 at digitalmars.com
Tue Nov 29 09:45:22 UTC 2022


On 11/29/2022 1:28 AM, Dark Hole wrote:
> ```d
> Xyzzy x = Xyzzy.busy;
> Xyzzy y = x.busy; // ok
> y = x.allow;      // runtime error
> y = ?x.allow ? x.allow : Xyzzy.busy;
> x = Xyzzy.allow(3);
> y = x.allow;      // ok
> ```
> 
> As I thought the type of `x.allow` is `int` and `x.busy` is (probably) `void`. 
> But then we assigning them to `y` which type is `Xyzzy`. How should it work?

An implicit cast.


> Implicit cast? Or it should be read like `y = ?x.allow ? x : assert(0)`?
> 
> Also what will be in `nothrow` code? Can we access members of sumtype?

Exceptions have nothing to do with sumtypes. The runtime error will be like a 
buffer overflow error.


More information about the Digitalmars-d mailing list