Fix #1001774: don't discard generated code

Also fix another instance of the same bug.