fix ternary if else generation (closes #2951)