Improve error reporting in interface typechecking
authorsimonpj@microsoft.com <unknown>
Thu, 25 May 2006 09:45:45 +0000 (09:45 +0000)
committersimonpj@microsoft.com <unknown>
Thu, 25 May 2006 09:45:45 +0000 (09:45 +0000)
compiler/iface/IfaceEnv.lhs
compiler/iface/IfaceSyn.lhs

index 40b7d31..3c1db55 100644 (file)
@@ -288,9 +288,10 @@ initOrigNames names = foldl extendOrigNameCache emptyModuleEnv names
 tcIfaceLclId :: OccName -> IfL Id
 tcIfaceLclId occ
   = do { lcl <- getLclEnv
 tcIfaceLclId :: OccName -> IfL Id
 tcIfaceLclId occ
   = do { lcl <- getLclEnv
-       ; return (lookupOccEnv (if_id_env lcl) occ
-                 `orElse` 
-                 pprPanic "tcIfaceLclId" (ppr occ)) }
+       ; case (lookupOccEnv (if_id_env lcl) occ) of
+            Just ty_var -> return ty_var
+            Nothing     -> failIfM (text "Iface id out of scope: " <+> ppr occ)
+        }
 
 refineIfaceIdEnv :: TypeRefinement -> IfL a -> IfL a
 refineIfaceIdEnv (tv_subst, _) thing_inside
 
 refineIfaceIdEnv :: TypeRefinement -> IfL a -> IfL a
 refineIfaceIdEnv (tv_subst, _) thing_inside
@@ -311,9 +312,10 @@ extendIfaceIdEnv ids thing_inside
 tcIfaceTyVar :: OccName -> IfL TyVar
 tcIfaceTyVar occ
   = do { lcl <- getLclEnv
 tcIfaceTyVar :: OccName -> IfL TyVar
 tcIfaceTyVar occ
   = do { lcl <- getLclEnv
-       ; return (lookupOccEnv (if_tv_env lcl) occ
-                 `orElse`
-                 pprPanic "tcIfaceTyVar" (ppr occ)) }
+       ; case (lookupOccEnv (if_tv_env lcl) occ) of
+            Just ty_var -> return ty_var
+            Nothing     -> failIfM (text "Iface type variable out of scope: " <+> ppr occ)
+        }
 
 extendIfaceTyVarEnv :: [TyVar] -> IfL a -> IfL a
 extendIfaceTyVarEnv tyvars thing_inside
 
 extendIfaceTyVarEnv :: [TyVar] -> IfL a -> IfL a
 extendIfaceTyVarEnv tyvars thing_inside
index d4a6eec..5309367 100644 (file)
@@ -654,7 +654,6 @@ toIfaceExpr ext (Lit l)       = IfaceLit l
 toIfaceExpr ext (Type ty)     = IfaceType (toIfaceType ext ty)
 toIfaceExpr ext (Lam x b)     = IfaceLam (toIfaceBndr ext x) (toIfaceExpr ext b)
 toIfaceExpr ext (App f a)     = toIfaceApp ext f [a]
 toIfaceExpr ext (Type ty)     = IfaceType (toIfaceType ext ty)
 toIfaceExpr ext (Lam x b)     = IfaceLam (toIfaceBndr ext x) (toIfaceExpr ext b)
 toIfaceExpr ext (App f a)     = toIfaceApp ext f [a]
--- gaw 2004
 toIfaceExpr ext (Case s x ty as) = IfaceCase (toIfaceExpr ext s) (getOccName x) (toIfaceType ext ty) (map (toIfaceAlt ext) as)
 toIfaceExpr ext (Let b e)     = IfaceLet (toIfaceBind ext b) (toIfaceExpr ext e)
 toIfaceExpr ext (Note n e)    = IfaceNote (toIfaceNote ext n) (toIfaceExpr ext e)
 toIfaceExpr ext (Case s x ty as) = IfaceCase (toIfaceExpr ext s) (getOccName x) (toIfaceType ext ty) (map (toIfaceAlt ext) as)
 toIfaceExpr ext (Let b e)     = IfaceLet (toIfaceBind ext b) (toIfaceExpr ext e)
 toIfaceExpr ext (Note n e)    = IfaceNote (toIfaceNote ext n) (toIfaceExpr ext e)