[project @ 1999-01-21 20:02:43 by sof]
authorsof <unknown>
Thu, 21 Jan 1999 20:02:45 +0000 (20:02 +0000)
committersof <unknown>
Thu, 21 Jan 1999 20:02:45 +0000 (20:02 +0000)
Robustified derived toEnum methods; gives better error message when
passed enum tags < 0.

ghc/compiler/prelude/PrelInfo.lhs
ghc/compiler/typecheck/TcGenDeriv.lhs

index 6c4049e..830247a 100644 (file)
@@ -606,7 +606,7 @@ deriving_occ_info
     , (ordClassKey,    [intTyCon_RDR, compose_RDR, eqTag_RDR])
                                -- EQ (from Ordering) is needed to force in the constructors
                                -- as well as the type constructor.
-    , (enumClassKey,   [intTyCon_RDR, map_RDR, plus_RDR, showsPrec_RDR, append_RDR]) 
+    , (enumClassKey,   [intTyCon_RDR, and_RDR, map_RDR, plus_RDR, showsPrec_RDR, append_RDR]) 
                                -- The last two Enum deps are only used to produce better
                                -- error msgs for derived toEnum methods.
     , (boundedClassKey,        [intTyCon_RDR])
index cab4e7c..09e4992 100644 (file)
@@ -483,11 +483,16 @@ gen_Enum_binds tycon
 
     to_enum
       = mk_easy_FunMonoBind tycon_loc toEnum_RDR [a_Pat] [] $
-       HsIf (HsApp (HsApp (HsVar gt_RDR) 
-                          (HsVar a_RDR))
-                          (HsVar (maxtag_RDR tycon)))
-            (illegal_toEnum_tag occ_nm (maxtag_RDR tycon))
+       HsIf (HsApp (HsApp 
+                   (HsVar and_RDR)
+                   (HsApp (HsApp (HsVar ge_RDR)
+                                 (HsVar a_RDR))
+                                 (HsLit (HsInt 0))))
+                    (HsApp (HsApp (HsVar le_RDR)
+                                 (HsVar a_RDR))
+                                 (HsVar (maxtag_RDR tycon))))
              (mk_easy_App (tag2con_RDR tycon) [a_RDR])
+            (illegal_toEnum_tag occ_nm (maxtag_RDR tycon))
             tycon_loc
 
     enum_from