Fix var type inference2

Giving it another try.
what if the rewrite isn't at the top? Is it correct to do nothing in that case?