Improve error recovery in the typechecker

Authored by simonpj on Mar 13 2019, 6:15 AM.

Description

Improve error recovery in the typechecker

Issue Trac #16418 showed that we were carrying on too eagerly after a bogus
type signature was identified (a bad telescope in fact), leading to a
subsequent crash.

This led me in to a maze of twisty little passages in the typechecker's
error recovery, and I ended up doing some refactoring in TcRnMonad.
Some specfifics

  • TcRnMonad.try_m is now called attemptM.
  • I switched the order of the result pair in tryTc, to make it consistent with other similar functions.
  • The actual exception used in the Tc monad is irrelevant so, to avoid polluting type signatures, I made tcTryM, a simple wrapper around tryM, and used it.

The more important changes are in

  • TcSimplify.captureTopConstraints, where we should have been calling simplifyTop rather than reportUnsolved, so that levity defaulting takes place properly.
  • TcUnify.emitResidualTvConstraint, where we need to set the correct status for a new implication constraint. (Previously we ended up with an Insoluble constraint wrapped in an Unsolved implication, which meant that insolubleWC gave the wrong answer.

(cherry picked from commit 4927117cd6166a97455d788dbf7433c95441b57a)

Details

Committed
bgamariNov 8 2019, 2:28 PM
Parents
rGHCbf5c4c194b68: Fix #17112
Branches
Unknown
Tags
Unknown