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

132 Views Asked by At

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?

1

There are 1 best solutions below

3
Colonel Thirty Two On BEST ANSWER

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));