From 7730713b747e66c93b4fe45478981a6e2ebfc7e2 Mon Sep 17 00:00:00 2001 From: Simon Peyton Jones Date: Mon, 15 Feb 2021 22:36:16 +0000 Subject: Unify result type earlier to improve error messages Ticket #19364 helpfully points out that we do not currently take advantage of pushing the result type of an application into the arguments. This makes error messages notably less good. The fix is rather easy: move the result-type unification step earlier. It's even a bit more efficient; in the the checking case we now do one less zonk. See Note [Unify with expected type before typechecking arguments] in GHC.Tc.Gen.App This change generally improves error messages, but it made one worse: typecheck/should_fail/T16204c. That led me to the realisation that a good error can be replaced by a less-good one, which provoked me to change GHC.Tc.Solver.Interact.inertsCanDischarge. It's explained in the new Note [Combining equalities] One other refactoring: I discovered that KindEqOrigin didn't need a Maybe in its type -- a nice simplification. --- testsuite/tests/typecheck/should_fail/T8450.stderr | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) (limited to 'testsuite/tests/typecheck/should_fail/T8450.stderr') diff --git a/testsuite/tests/typecheck/should_fail/T8450.stderr b/testsuite/tests/typecheck/should_fail/T8450.stderr index 9ac0d63643..8ba84a76f1 100644 --- a/testsuite/tests/typecheck/should_fail/T8450.stderr +++ b/testsuite/tests/typecheck/should_fail/T8450.stderr @@ -1,15 +1,11 @@ -T8450.hs:8:19: error: - • Couldn't match type ‘a’ with ‘Bool’ - Expected: Either Bool () - Actual: Either a () +T8450.hs:8:7: error: + • Couldn't match expected type ‘a’ with actual type ‘()’ ‘a’ is a rigid type variable bound by the type signature for: run :: forall a. a at T8450.hs:7:1-18 - • In the second argument of ‘($)’, namely - ‘(undefined :: Either a ())’ - In the expression: runEffect $ (undefined :: Either a ()) + • In the expression: runEffect $ (undefined :: Either a ()) In an equation for ‘run’: run = runEffect $ (undefined :: Either a ()) • Relevant bindings include run :: a (bound at T8450.hs:8:1) -- cgit v1.2.1