Optimization removes an assignment to variable
cardillan opened this issue · comments
Cardillan commented
The following code
alive = @unit.dead === 0
if alive
print(alive)
end
compiled with optimization produces:
sensor __tmp0 @unit @dead
jump 4 notEqual __tmp0 0
print alive
jump 4 always 0 0
end
A correct result would be more akin to this:
sensor __tmp0 @unit @dead
op strictEqual alive __tmp0 0
jump 4 equal alive 0
print alive
jump 4 always 0 0
end
I don't think it's caused by dead code elimination, as alive
is clearly used. Other optimization probably should only remove variables that are created by the compiler itself (the __tmp
ones) -- that could be an easy check to add.
I'll try to fix the issue, I'm putting it here for reference.
(Edited to fix the examples.)