factor check for assignment-to-constant into a function; improve its error output; closes #122