dphobos

Why does Nullable!(Nullable!int) refuse to compile?


The following code refuses to compile:

Nullable!(Nullable!int) nni = Nullable!(Nullable!int)(10);

With this error message:

Error: inout method nullable.Nullable!(Nullable!(immutable(int))).Nullable.this is not callable using a mutable object

Why?


Solution

  • It seems like a bad error message.

    The argument to the constructor of Nullable!(T) is T. In this case, T is a Nullable!int, but you're passing in an int. You need to wrap the int in a nullable.

    Nullable!(Nullable!int) foo = Nullable!(Nullable!int)(Nullable!int(10));