The code generator was sharing some temporary variables whereas it should not because some pointers to fields in these temporary variables are used later.
In the following example the function 'test' is compiled wrong because:
dt1:date builds a temporary object 't1' with type 'Date'.
then dt1:date:days returns a pointer 'p1' to 't1' because 'days' is the only field of the 'Date' type.
dt2:date builds a temporary object 't2' with type 'Date'.
then dt2:date:days returns a pointer 'p2' to 't2'.
The trouble is that the optimizer decides to share the temporary objects 't1' and 't2' because it does not see that unreferencing the pointers 'p1' and 'p2' truly means using 't1' and 't2'.
As a result, the 'test' function will return 0.
var DateTime dt1 := datetime 1999 2 2 14 0 0 0.0
var DateTime dt2 := datetime 1999 1 27 23 0 0 0.0
function test -> i
arg Int i
i := dt1:date:days-dt2:date:days
console (cast test Str)+"[lf]"