Improve error message for invalid patterns in guards and matches

Closes #1092