-
Notifications
You must be signed in to change notification settings - Fork 1
Null
null is a special keyword in BType. Unlike other languages, null is both dynamic and static. At a high level, null represents the same empty value in all circumstances. However, null is also typed: null assigned to a variable of type foo<bar> cannot be assigned to a variable of type abc<def>.
null is an exception to the normal type inference rules. Ordinarily, variable declarations without a type (i.e.: those using the var keyword) will detect the type of whatever they are being assigned. null in this case is an invalid option, as var x = null; provides no indication of the general type which null is applied to. Instead, the type must be provided explicitly: foo<bar>:x = null;
Internally, null references heap location 0, which is an invalid location to assign values (the first portion of the heap contains information about memory allocation; the lowest possible pointer value is one byte beyond the end of this section).
null cannot be used as a value in a tuple:
var x = [: 123, false, null]; # INVALID!
This is because null is untyped. The type of the tuple cannot be resolved because no type exists for the third element. In order to accomplish this, use a typecast:
var x = [: 123, false, null as Foo]; # Valid