[project @ 2003-08-19 22:09:09 by krc]
authorkrc <unknown>
Tue, 19 Aug 2003 22:09:10 +0000 (22:09 +0000)
committerkrc <unknown>
Tue, 19 Aug 2003 22:09:10 +0000 (22:09 +0000)
External Core programs sometimes contain newtype declarations with no
data constructors. GHC expected every newtype declaration to have at
least one data constructor, so it would previously fail with an "empty list"
error if you tried to compile such a program. These declarations are handled
properly now.

ghc/compiler/main/HscTypes.lhs
ghc/compiler/prelude/PrelNames.lhs
ghc/compiler/typecheck/TcTyClsDecls.lhs

index c8cf4c7..88fd6b9 100644 (file)
@@ -457,7 +457,7 @@ implicitTyThings things
        -- Newtypes don't have a worker Id, so don't generate that
     extras (ATyCon tc) = map AnId (tyConGenIds tc ++ tyConSelIds tc) ++ data_con_stuff
        where
-       data_con_stuff | isNewTyCon tc = [ADataCon dc1, AnId (dataConWrapId dc1)]
+       data_con_stuff | isNewTyCon tc = (if (null dcs) then [] else  [ADataCon dc1, AnId (dataConWrapId dc1)]) 
                       | otherwise     = concatMap (extras_plus . ADataCon) dcs
        dcs = tyConDataCons tc
        dc1 = head dcs
index 1c597a8..bacb0ec 100644 (file)
@@ -324,7 +324,8 @@ mkTupNameStr Boxed 3 = (pREL_TUP_Name, mkFastString "(,,)")  -- ditto
 mkTupNameStr Boxed 4 = (pREL_TUP_Name, mkFastString "(,,,)") -- ditto
 mkTupNameStr Boxed n = (pREL_TUP_Name, mkFastString ("(" ++ nOfThem (n-1) ',' ++ ")"))
 
-mkTupNameStr Unboxed 0 = panic "Name.mkUbxTupNameStr: 0 ???"
+mkTupNameStr Unboxed 0 = (gHC_PRIM_Name, mkFastString "(# #)") -- 1 and 0 both make sense!!!
+--panic "Name.mkUbxTupNameStr: 0 ???"
 mkTupNameStr Unboxed 1 = (gHC_PRIM_Name, mkFastString "(# #)") -- 1 and 0 both make sense!!!
 mkTupNameStr Unboxed 2 = (gHC_PRIM_Name, mkFastString "(#,#)")
 mkTupNameStr Unboxed 3 = (gHC_PRIM_Name, mkFastString "(#,,#)")
index 45da667..378dc35 100644 (file)
@@ -411,6 +411,8 @@ mkNewTyConRep :: TyCon              -- The original type constructor
 -- The trick is to to deal correctly with recursive newtypes
 -- such as     newtype T = MkT T
 
+-- a newtype with no data constructors -- appears in External Core programs
+mkNewTyConRep tc | (null (tyConDataCons tc)) = unitTy
 mkNewTyConRep tc
   = go [] tc
   where