Make tyConSingleDataCon_maybe more forgiving
authorsimonpj@microsoft.com <unknown>
Thu, 8 Oct 2009 16:23:29 +0000 (16:23 +0000)
committersimonpj@microsoft.com <unknown>
Thu, 8 Oct 2009 16:23:29 +0000 (16:23 +0000)
This function was barfing on a type family tycon; which in turn
crashed the compiler (when -ticky is in use) because of the use in
CmmTicky.hs.  There's no need for it to reject such tycons, so I just
made it return Nothing rather than falling over.

compiler/types/TyCon.lhs

index a7b0594..bb21536 100644 (file)
@@ -1097,13 +1097,10 @@ synTyConResKind tycon  = pprPanic "synTyConResKind" (ppr tycon)
 -- has more than one constructor, or represents a primitive or function type constructor then
 -- @Nothing@ is returned. In any other case, the function panics
 tyConSingleDataCon_maybe :: TyCon -> Maybe DataCon
-tyConSingleDataCon_maybe (AlgTyCon {algTcRhs = DataTyCon {data_cons = [c] }}) = Just c
-tyConSingleDataCon_maybe (AlgTyCon {algTcRhs = NewTyCon { data_con = c }})    = Just c
-tyConSingleDataCon_maybe (AlgTyCon {})          = Nothing
-tyConSingleDataCon_maybe (TupleTyCon {dataCon = con}) = Just con
-tyConSingleDataCon_maybe (PrimTyCon {})               = Nothing
-tyConSingleDataCon_maybe (FunTyCon {})                = Nothing  -- case at funty
-tyConSingleDataCon_maybe tc = pprPanic "tyConSingleDataCon_maybe: unexpected tycon " $ ppr tc
+tyConSingleDataCon_maybe (TupleTyCon {dataCon = c})                           = Just c
+tyConSingleDataCon_maybe (AlgTyCon {algTcRhs = DataTyCon { data_cons = [c] }}) = Just c
+tyConSingleDataCon_maybe (AlgTyCon {algTcRhs = NewTyCon { data_con = c }})     = Just c
+tyConSingleDataCon_maybe _                                                    = Nothing
 \end{code}
 
 \begin{code}