Improve invalid match and guard errors, closes #1673