[RFC] Throwing an exception with null pointers
GrimMaple
grimmaple95 at gmail.com
Mon Apr 21 10:34:28 UTC 2025
On Saturday, 12 April 2025 at 23:11:41 UTC, Richard (Rikki)
Andrew Cattermole wrote:
> ## Language support
FYI, some time ago I designed this
https://github.com/GrimMaple/mud/blob/master/source/mud/nullable.d to work as sort-of C#-like Nullable checks (that work if you `<Nullable>enable</Nullable>`). My intention was to include it in OpenD to work like this:
When a compiler flag is enabled (eg -nullcheck), the code below:
```d
Object o = new Object();
```
Would be then silently rewritten by compiler as
```
NotNull!Object o = new Object();
```
thus enabling compile-time null checks.
The solution is not perfect and needs some further compiler work
(eg checking if some field is inderectly initialized by some func
called in a constructor). Also, I lack dmd knowledge to insert
this myself, so this didn't go anywhere in terms of actual
inclusion, but I might give it a go some time in the future.
More information about the Digitalmars-d
mailing list