draft proposal for Sum Types for D

cc cc at nevernet.com
Thu Dec 1 05:49:56 UTC 2022


On Tuesday, 29 November 2022 at 06:26:20 UTC, Walter Bright wrote:
> Go ahead, Make My Day! Destroy!
>
> https://github.com/WalterBright/DIPs/blob/sumtypes/DIPs/1NNN-(wgb).md

```d
if (?ret.Error)
```
I imagine some stubbed toes writing `if (ret.Error)` without the 
`?` for a while, and potential unnoticed bugs when it works by 
accident.  I like the recentish trend of D compiler errors 
suggesting "Did you mean to use..." but would that be suitable 
for a runtime error message?

Also, would this syntax preclude us from having C#-style 
[null-conditional 
operators](https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/operators/member-access-operators#null-conditional-operators--and-) someday? e.g.
```d
class Foo {...}
Foo a = new Foo;
Foo b = null;
auto res = a?.bar(); // Ok
res = b?.bar();      // returns null (returntype.init for value 
types?)
```


More information about the Digitalmars-d mailing list