[RFC] Throwing an exception with null pointers

Richard (Rikki) Andrew Cattermole richard at cattermole.co.nz
Mon Apr 21 10:45:15 UTC 2025


On 21/04/2025 10:34 PM, GrimMaple wrote:
> 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.

That is the Swift solution to the problem, more or less.



More information about the Digitalmars-d mailing list