KJ-4 Convert typed expressions into expressions with casts .
Corrected bugs introduced two commits ago. All tests should pass.