[commit: ghc] master: Fix over-eager error suppression in TcErrors (c81f66c)

git at git.haskell.org git at git.haskell.org
Wed Oct 11 12:30:16 UTC 2017


Repository : ssh://git@git.haskell.org/ghc

On branch  : master
Link       : http://ghc.haskell.org/trac/ghc/changeset/c81f66ccafdb4c6c7a09cfaf6819c8797c518491/ghc

>---------------------------------------------------------------

commit c81f66ccafdb4c6c7a09cfaf6819c8797c518491
Author: Simon Peyton Jones <simonpj at microsoft.com>
Date:   Thu Oct 5 17:40:28 2017 +0100

    Fix over-eager error suppression in TcErrors
    
    See Note [Given insolubles] in TcRnTypes
    
    Fixes Trac #14325.


>---------------------------------------------------------------

c81f66ccafdb4c6c7a09cfaf6819c8797c518491
 compiler/typecheck/TcRnTypes.hs                 | 24 ++++++++++++++++++++++--
 testsuite/tests/typecheck/should_fail/T14325.hs | 11 +++++++++++
 testsuite/tests/typecheck/should_fail/all.T     |  1 +
 3 files changed, 34 insertions(+), 2 deletions(-)

diff --git a/compiler/typecheck/TcRnTypes.hs b/compiler/typecheck/TcRnTypes.hs
index ba0777b..3c7d67f 100644
--- a/compiler/typecheck/TcRnTypes.hs
+++ b/compiler/typecheck/TcRnTypes.hs
@@ -2319,7 +2319,7 @@ trulyInsoluble :: Ct -> Bool
 -- Yuk!
 trulyInsoluble insol
   | isHoleCt insol = isOutOfScopeCt insol
-  | otherwise      = True
+  | otherwise      = not (isGivenCt insol) -- See Note [Given insolubles]
 
 instance Outputable WantedConstraints where
   ppr (WC {wc_simple = s, wc_impl = i, wc_insol = n})
@@ -2334,7 +2334,27 @@ ppr_bag doc bag
  | otherwise      = hang (doc <+> equals)
                        2 (foldrBag (($$) . ppr) empty bag)
 
-{-
+{- Note [Given insolubles]
+~~~~~~~~~~~~~~~~~~~~~~~~~~
+Consider (Trac #14325, comment:)
+    class (a~b) => C a b
+
+    foo :: C a b => a -> b
+    foo x = x
+
+    hm3 :: C (f b) b => b -> f b
+    hm3 x = foo x
+
+From the [G] C (f b) b we get the insoluble [G] f b ~# b.  Then we we also
+get an unsolved [W] C b (f b).  If trulyInsouble is true of this, we'll
+set cec_suppress to True, and suppress reports of the [W] C b (f b).  But we
+may not report the insoluble [G] f b ~# b either (see Note [Given errors]
+in TcErrors), so we may fail to report anything at all!  Yikes.
+
+Bottom line: we must be certain to report anything trulyInsoluble.  Easiest
+way to guaranteed this is to make truly Insoluble false of Givens.
+
+
 ************************************************************************
 *                                                                      *
                 Implication constraints
diff --git a/testsuite/tests/typecheck/should_fail/T14325.hs b/testsuite/tests/typecheck/should_fail/T14325.hs
new file mode 100644
index 0000000..edb6038
--- /dev/null
+++ b/testsuite/tests/typecheck/should_fail/T14325.hs
@@ -0,0 +1,11 @@
+{-# LANGUAGE GADTs, MultiParamTypeClasses #-}
+
+module T14325 where
+
+class (a~b) => C a b
+
+foo :: C a b => a -> b
+foo x = x
+
+hm3 :: C (f b) b => b -> f b
+hm3 x = foo x
diff --git a/testsuite/tests/typecheck/should_fail/all.T b/testsuite/tests/typecheck/should_fail/all.T
index fe71e37..381e2c5 100644
--- a/testsuite/tests/typecheck/should_fail/all.T
+++ b/testsuite/tests/typecheck/should_fail/all.T
@@ -458,3 +458,4 @@ test('T14055', normal, compile_fail, [''])
 test('T13909', normal, compile_fail, [''])
 test('T13929', normal, compile_fail, [''])
 test('T14232', normal, compile_fail, [''])
+test('T14325', normal, compile_fail, [''])



More information about the ghc-commits mailing list