Refactoring: define TcRnMonad.failWith and use it in the renamer
authorsimonpj@microsoft.com <unknown>
Tue, 12 Aug 2008 08:22:55 +0000 (08:22 +0000)
committersimonpj@microsoft.com <unknown>
Tue, 12 Aug 2008 08:22:55 +0000 (08:22 +0000)
compiler/rename/RnExpr.lhs
compiler/rename/RnTypes.lhs
compiler/typecheck/TcRnMonad.lhs

index 7074993..716a7a2 100644 (file)
@@ -564,9 +564,7 @@ rnBracket (VarBr n) = do { name <- lookupOccRn n
 rnBracket (ExpBr e) = do { (e', fvs) <- rnLExpr e
                         ; return (ExpBr e', fvs) }
 
-rnBracket (PatBr _) = do { addErr (ptext (sLit "Tempate Haskell pattern brackets are not supported yet"));
-                           failM }
-
+rnBracket (PatBr _) = failWith (ptext (sLit "Tempate Haskell pattern brackets are not supported yet"))
 rnBracket (TypBr t) = do { (t', fvs) <- rnHsTypeFVs doc t
                         ; return (TypBr t', fvs) }
                    where
@@ -930,8 +928,7 @@ rn_rec_stmt_lhs fix_env (L loc (BindStmt pat expr a b))
                fv_pat)]
 
 rn_rec_stmt_lhs _ (L _ (LetStmt binds@(HsIPBinds _)))
-  = do { addErr (badIpBinds (ptext (sLit "an mdo expression")) binds)
-       ; failM }
+  = failWith (badIpBinds (ptext (sLit "an mdo expression")) binds)
 
 rn_rec_stmt_lhs fix_env (L loc (LetStmt (HsValBinds binds))) 
     = do binds' <- rnValBindsLHS fix_env binds
@@ -993,8 +990,7 @@ rn_rec_stmt _ (L loc (BindStmt pat' expr _ _)) fv_pat
              L loc (BindStmt pat' expr' bind_op fail_op))]
 
 rn_rec_stmt _ (L _ (LetStmt binds@(HsIPBinds _))) _
-  = do { addErr (badIpBinds (ptext (sLit "an mdo expression")) binds)
-       ; failM }
+  = failWith (badIpBinds (ptext (sLit "an mdo expression")) binds)
 
 rn_rec_stmt all_bndrs (L loc (LetStmt (HsValBinds binds'))) _ = do 
   (binds', du_binds) <- 
index 20803be..7a0948e 100644 (file)
@@ -170,9 +170,8 @@ rnHsType doc (HsPredTy pred) = do
     pred' <- rnPred doc pred
     return (HsPredTy pred')
 
-rnHsType _ (HsSpliceTy _) = do
-    addErr (ptext (sLit "Type splices are not yet implemented"))
-    failM
+rnHsType _ (HsSpliceTy _) =
+    failWith (ptext (sLit "Type splices are not yet implemented"))
 
 rnHsType doc (HsDocTy ty haddock_doc) = do
     ty' <- rnLHsType doc ty
index 1f02518..2b7e567 100644 (file)
@@ -464,9 +464,12 @@ getErrsVar = do { env <- getLclEnv; return (tcl_errs env) }
 setErrsVar :: TcRef Messages -> TcRn a -> TcRn a
 setErrsVar v = updLclEnv (\ env -> env { tcl_errs =  v })
 
-addErr :: Message -> TcRn ()
+addErr :: Message -> TcRn ()   -- Ignores the context stack
 addErr msg = do { loc <- getSrcSpanM ; addErrAt loc msg }
 
+failWith :: Message -> TcRn a
+failWith msg = addErr msg >> failM
+
 addLocErr :: Located e -> (e -> Message) -> TcRn ()
 addLocErr (L loc e) fn = addErrAt loc (fn e)