Improved typechecker error handling significantly.

Also added a few test cases to ensure all error messages are correct and error recovery is functional.