The null coalescing operator, represented as two consecutive question marks ?? take a nullable type or a reference type in its first operand. If the first operand is a nullable type, the second operand must belong to the same nullable type or the base type of the nullable type. If the first operand is a reference type, the second type must belong to the same type, or to a derived type.
When the first operand is a nullable type, the following rules apply:
An expression like this:
operand1 ?? operand2
is translated this way, in terms of the conditional expression:
if operand1.HasValue then operand1.GetValueOrDefault else operand2
The first operand, however, is evaluated only once, and the compiler duplicates the value at the top of the evaluation stack after generating the value for the first operand.
As an alternative, the type of the first operand may be a reference type. In that case:
An expression like this:
operand1 ?? operand2
is translated this way, in terms of the conditional expression:
if operand1 <> nil then operand1 else operand2
Again, operand1 is evaluated only once.
The Freya Programming Language
Expressions
Nullable types
Conditional expressions
Type declarations