[commit: ghc] master: Fix #9415. (1b13886)

git at git.haskell.org git at git.haskell.org
Tue Aug 12 15:46:18 UTC 2014


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

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

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

commit 1b1388697e687154c2bf1943639e75f3ccf5bc59
Author: Richard Eisenberg <eir at cis.upenn.edu>
Date:   Wed Aug 6 09:51:26 2014 -0400

    Fix #9415.
    
    Abort typechecking when we detect a superclass cycle error, as
    ambiguity checking in the presence of superclass cycle errors can
    cause a loop.


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

1b1388697e687154c2bf1943639e75f3ccf5bc59
 compiler/typecheck/TcTyClsDecls.lhs | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)

diff --git a/compiler/typecheck/TcTyClsDecls.lhs b/compiler/typecheck/TcTyClsDecls.lhs
index f09bef8..2db31e3 100644
--- a/compiler/typecheck/TcTyClsDecls.lhs
+++ b/compiler/typecheck/TcTyClsDecls.lhs
@@ -1369,10 +1369,24 @@ since GADTs are not kind indexed.
 Validity checking is done once the mutually-recursive knot has been
 tied, so we can look at things freely.
 
+Note [Abort when superclass cycle is detected]
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+We must avoid doing the ambiguity check when there are already errors accumulated.
+This is because one of the errors may be a superclass cycle, and superclass cycles
+cause canonicalization to loop. Here is a representative example:
+
+  class D a => C a where
+    meth :: D a => ()
+  class C a => D a
+
+This fixes Trac #9415.
+
 \begin{code}
 checkClassCycleErrs :: Class -> TcM ()
 checkClassCycleErrs cls
-  = unless (null cls_cycles) $ mapM_ recClsErr cls_cycles
+  = unless (null cls_cycles) $
+    do { mapM_ recClsErr cls_cycles
+       ; failM }  -- See Note [Abort when superclass cycle is detected]
   where cls_cycles = calcClassCycles cls
 
 checkValidTyCl :: TyThing -> TcM ()
@@ -1623,6 +1637,7 @@ checkValidClass cls
         ; checkValidTheta (ClassSCCtxt (className cls)) theta
 
           -- Now check for cyclic superclasses
+          -- If there are superclass cycles, checkClassCycleErrs bails.
         ; checkClassCycleErrs cls
 
         -- Check the class operations



More information about the ghc-commits mailing list