How to check if value is null, today?
schveiguy at gmail.com
Thu Oct 14 15:27:27 UTC 2021
On 10/14/21 7:58 AM, tastyminerals wrote:
> The new `DMD v2.097.2` deprecated implicit null conversions
> The deprecation warning tell you to `Please use .get explicitly.`.
> Here is an example code that doesn't work with the new compiler anymore:
> if (someValue.isNull)
> Attempting to run the above throws:
> Error: incompatible types for `(0) : (someValue)`: `int` and `Nullable!int`
> I am not sure I understand what kind of `.get` overload are we supposed
> to use here. I tried to read the documentation but looks like it is yet
> to be updated.
> Can somebody please help me out?
I think your expression is something more like:
someValue.isNull ? 0 : someValue;
Due to the error message format. You need to call `get` explicitly to
unwrap a Nullable now. So change it to:
someValue.isNull ? 0 : someValue.get;
or even better:
which uses the default value of 0 if it's null.
More information about the Digitalmars-d-learn