fix: harden flatten for illegal calls flatten(<ideal>)