[fpc-devel] "Default" discussion for SmartPointers etc

Stefan Glienke sglienke at dsharp.org
Thu Jul 28 13:02:31 CEST 2016

One thing that I did not see mentioned here is the fact that introducing
"operator hoisting" by introducing that default feature will not solve nullables
at all.

I think a basic rule of nullables (at least in C# where I know them from) is the
fact that operators can only be applied to a nullable if the underlying type
supports them. But the result of an operation that involves a nullable will
always be a nullable (because it can happen than any of the operants is null).

That means that a := b + c where b or/and c are nullable<int> always causes a to
be nullable<int>. Just introducing default where the addition will be performed
by the underlying value is not enough because a) the result (if both are not
null) has to be converted back into a nullable<int> and b) the result needs to
be null if either b or c happen to be null. Both cannot be done by just
promoting the addition operator. Because if b or c happen to be null an
assignment to an integer would raise an error (at least in C# that is the case -
see https://msdn.microsoft.com/en-us/library/ydkbatt6(v=vs.110).aspx)

More information about the fpc-devel mailing list