Using Option Strict On
is a pretty good way to avoid such surprises. You get "what the hell are you trying to do?" error message from the compiler.
But with this Off, these are valid statements performed by DLR, Dynamic Language Runtime. Which is able to appreciate late expressions like this. However, does it have a null type problem of type Integer?
. It must deal with a boxed version of the value. It is just nothing. And nothing has any type information associated with it. Nothing can do DLR to see that it started as a whole integer with a zero value, since it all knows that it could be a string that is nothing.
The compiler also cannot help, it cannot emit any code to force the expression to follow normal evaluation rules. All he knows is that there is some function, she does not know who, whose name is "MyFunction", has no idea what value it returns. He passes the dollar to DLR to sort it.
So DLR just shoots him. And he comes up with the sentence “No idea” + 0 = 0. Given that he has type information for 0. This is Integer, so he tries to interpret the left operator as a whole. What really is Nothing is the correct default value for Integer.
Function, not error.
source share