Treat () as an enumeration tycon
authorIan Lynagh <igloo@earth.li>
Tue, 24 Nov 2009 01:13:13 +0000 (01:13 +0000)
committerIan Lynagh <igloo@earth.li>
Tue, 24 Nov 2009 01:13:13 +0000 (01:13 +0000)
This fixes deriving Ord (), which previously failed with
  ghc-stage1: panic! (the 'impossible' happened)
    (GHC version 6.13.20091123 for x86_64-unknown-linux):
          TcGenDeriv:mk_FunBind

compiler/types/TyCon.lhs

index 43fb524..958a0cb 100644 (file)
@@ -864,6 +864,7 @@ isGadtSyntaxTyCon _                                    = False
 -- | Is this an algebraic 'TyCon' which is just an enumeration of values?
 isEnumerationTyCon :: TyCon -> Bool
 isEnumerationTyCon (AlgTyCon {algTcRhs = DataTyCon { is_enum = res }}) = res
+isEnumerationTyCon (TupleTyCon {tyConArity = arity}) = arity == 0
 isEnumerationTyCon _                                                   = False
 
 -- | Is this a 'TyCon', synonym or otherwise, that may have further instances appear?
@@ -1093,8 +1094,9 @@ tyConFamilySize other = pprPanic "tyConFamilySize:" (ppr other)
 -- | Extract an 'AlgTyConRhs' with information about data constructors from an algebraic or tuple
 -- 'TyCon'. Panics for any other sort of 'TyCon'
 algTyConRhs :: TyCon -> AlgTyConRhs
-algTyConRhs (AlgTyCon {algTcRhs = rhs})  = rhs
-algTyConRhs (TupleTyCon {dataCon = con}) = DataTyCon { data_cons = [con], is_enum = False }
+algTyConRhs (AlgTyCon {algTcRhs = rhs}) = rhs
+algTyConRhs (TupleTyCon {dataCon = con, tyConArity = arity})
+    = DataTyCon { data_cons = [con], is_enum = arity == 0 }
 algTyConRhs other = pprPanic "algTyConRhs" (ppr other)
 \end{code}