projects
/
ghc-hetmet.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Fix Trac #745: improve error recoevery for type signatures
[ghc-hetmet.git]
/
compiler
/
typecheck
/
TcRnMonad.lhs
diff --git
a/compiler/typecheck/TcRnMonad.lhs
b/compiler/typecheck/TcRnMonad.lhs
index
804098a
..
309ce5b
100644
(file)
--- a/
compiler/typecheck/TcRnMonad.lhs
+++ b/
compiler/typecheck/TcRnMonad.lhs
@@
-40,10
+40,10
@@
import StaticFlags
import FastString
import Panic
import Util
import FastString
import Panic
import Util
-
+import Exception
+
import System.IO
import Data.IORef
import System.IO
import Data.IORef
-import Control.Exception
import Control.Monad
\end{code}
import Control.Monad
\end{code}
@@
-103,7
+103,7
@@
initTc hsc_env hsc_src keep_rn_syntax mod do_this
tcg_rn_decls = maybe_rn_syntax emptyRnGroup,
tcg_binds = emptyLHsBinds,
tcg_rn_decls = maybe_rn_syntax emptyRnGroup,
tcg_binds = emptyLHsBinds,
- tcg_deprecs = NoDeprecs,
+ tcg_warns = NoWarnings,
tcg_insts = [],
tcg_fam_insts= [],
tcg_rules = [],
tcg_insts = [],
tcg_fam_insts= [],
tcg_rules = [],
@@
-324,6
+324,10
@@
newSysLocalIds :: FastString -> [TcType] -> TcRnIf gbl lcl [TcId]
newSysLocalIds fs tys
= do { us <- newUniqueSupply
; return (zipWith (mkSysLocal fs) (uniqsFromSupply us) tys) }
newSysLocalIds fs tys
= do { us <- newUniqueSupply
; return (zipWith (mkSysLocal fs) (uniqsFromSupply us) tys) }
+
+instance MonadUnique (IOEnv (Env gbl lcl)) where
+ getUniqueM = newUnique
+ getUniqueSupplyM = newUniqueSupply
\end{code}
\end{code}
@@
-361,7
+365,11
@@
traceOptTcRn flag doc = ifOptM flag $ do
dumpTcRn :: SDoc -> TcRn ()
dumpTcRn doc = do { rdr_env <- getGlobalRdrEnv ;
dflags <- getDOpts ;
dumpTcRn :: SDoc -> TcRn ()
dumpTcRn doc = do { rdr_env <- getGlobalRdrEnv ;
dflags <- getDOpts ;
- liftIO (printForUser stderr (mkPrintUnqualified dflags rdr_env) doc) }
+ liftIO (printForUser stderr (mkPrintUnqualified dflags rdr_env) doc) }
+
+debugDumpTcRn :: SDoc -> TcRn ()
+debugDumpTcRn doc | opt_NoDebugOutput = return ()
+ | otherwise = dumpTcRn doc
dumpOptTcRn :: DynFlag -> SDoc -> TcRn ()
dumpOptTcRn flag doc = ifOptM flag (dumpTcRn doc)
dumpOptTcRn :: DynFlag -> SDoc -> TcRn ()
dumpOptTcRn flag doc = ifOptM flag (dumpTcRn doc)
@@
-456,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 })
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 }
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)
addLocErr :: Located e -> (e -> Message) -> TcRn ()
addLocErr (L loc e) fn = addErrAt loc (fn e)
@@
-533,7
+544,11
@@
discardWarnings thing_inside
\begin{code}
\begin{code}
+#if __GLASGOW_HASKELL__ < 609
try_m :: TcRn r -> TcRn (Either Exception r)
try_m :: TcRn r -> TcRn (Either Exception r)
+#else
+try_m :: TcRn r -> TcRn (Either ErrorCall r)
+#endif
-- Does try_m, with a debug-trace on failure
try_m thing
= do { mb_r <- tryM thing ;
-- Does try_m, with a debug-trace on failure
try_m thing
= do { mb_r <- tryM thing ;
@@
-560,7
+575,7
@@
mapAndRecoverM :: (a -> TcRn b) -> [a] -> TcRn [b]
-- Drop elements of the input that fail, so the result
-- list can be shorter than the argument list
mapAndRecoverM _ [] = return []
-- Drop elements of the input that fail, so the result
-- list can be shorter than the argument list
mapAndRecoverM _ [] = return []
-mapAndRecoverM f (x:xs) = do { mb_r <- tryM (f x)
+mapAndRecoverM f (x:xs) = do { mb_r <- try_m (f x)
; rs <- mapAndRecoverM f xs
; return (case mb_r of
Left _ -> rs
; rs <- mapAndRecoverM f xs
; return (case mb_r of
Left _ -> rs