Fixes for bugs in scalar lifting case exposed by foreach branch