Rewrite tests that got disabled by constant folding

Some tests become useless once constant folding has bee used. A few
bugfixes were found while disabling the optimization, I add them here
with a test case that prevents constant folding.