Improve typechecker error messages; see Trac #1221