Thread overview
How to check if value is null, today?
Oct 14
jfondren
October 14

The new DMD v2.097.2 deprecated implicit null conversions std.typecons.Nullable!double.Nullable.get_.

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?

October 14

On Thursday, 14 October 2021 at 11:58:29 UTC, tastyminerals wrote:

>

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`

Do you have a complete example? Because this runs without error:

import std.typecons : nullable, Nullable;
import std.stdio : writeln;

void main() {
    auto a = nullable(1);
    auto b = Nullable!int.init;
    if (!a.isNull)
        writeln(a.get);
    if (b.isNull)
        writeln("b is null");
}
October 14

On 10/14/21 7:58 AM, tastyminerals wrote:

>

The new DMD v2.097.2 deprecated implicit null conversions std.typecons.Nullable!double.Nullable.get_.

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:

someValue.get(0);

which uses the default value of 0 if it's null.

-Steve

October 15

On Thursday, 14 October 2021 at 12:43:36 UTC, jfondren wrote:

>

On Thursday, 14 October 2021 at 11:58:29 UTC, tastyminerals wrote:

>

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`

Do you have a complete example? Because this runs without error:

import std.typecons : nullable, Nullable;
import std.stdio : writeln;

void main() {
    auto a = nullable(1);
    auto b = Nullable!int.init;
    if (!a.isNull)
        writeln(a.get);
    if (b.isNull)
        writeln("b is null");
}

Steven Schveighoffer was correct, the error was caused by non explicit someVar; which had to be changed to someVar.get;.

October 15

On 10/15/21 6:39 AM, tastyminerals wrote:

>

On Thursday, 14 October 2021 at 12:43:36 UTC, jfondren wrote:

> >

Do you have a complete example? Because this runs without error:

>

Steven Schveighoffer was correct, the error was caused by non explicit someVar; which had to be changed to someVar.get;.

As a note for future reference, as jfondren says it's always good to post the exact code that is failing, better yet a complete example we can run. Often times people (including myself and many long-time users) come here puzzled about some message, but we have focused our brain on something that we think is causing the problem, but it isn't. Just posting that small piece brings us into your focused confusion instead of really looking at the big picture ;)

-Steve