From 0a09f3e0b2f25c02589f5e10b4235303cd218d79 Mon Sep 17 00:00:00 2001 From: hallgren Date: Mon, 25 Jun 2012 14:01:58 +0000 Subject: Check monad: support for accumulated errors In addition to warnings, the Check monad in GF.Infra.CheckM can now accumulate errors. There are two new functions checkAccumError: Message -> Check () accumulateError :: (a -> Check a) -> a -> Check a The former (with the same type as checkWarn) is used to report an accumulated (nonfatal) error. The latter converts fatal errors into accumulated errors. Accumulated errors are reported as regular errors by runCheck. Also, the Check monad type has been made abstract. --- src/compiler/GF/Compile/TypeCheck/ConcreteNew.hs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/compiler/GF/Compile') diff --git a/src/compiler/GF/Compile/TypeCheck/ConcreteNew.hs b/src/compiler/GF/Compile/TypeCheck/ConcreteNew.hs index 4ece28cda..26308d945 100644 --- a/src/compiler/GF/Compile/TypeCheck/ConcreteNew.hs +++ b/src/compiler/GF/Compile/TypeCheck/ConcreteNew.hs @@ -458,7 +458,7 @@ data MetaValue type MetaStore = IntMap.IntMap MetaValue data TcResult a = TcOk a MetaStore [Message] - | TcFail [Message] + | TcFail [Message] -- First msg is error, the rest are warnings? newtype TcM a = TcM {unTcM :: MetaStore -> [Message] -> TcResult a} instance Monad TcM where @@ -480,9 +480,9 @@ tcWarn :: Message -> TcM () tcWarn msg = TcM (\ms msgs -> TcOk () ms ((text "Warning:" <+> msg) : msgs)) runTcM :: TcM a -> Check a -runTcM f = Check (\ctxt msgs -> case unTcM f IntMap.empty msgs of - TcOk x _ msgs -> Success x msgs - TcFail msgs -> Fail msgs) +runTcM f = case unTcM f IntMap.empty [] of + TcOk x _ msgs -> do checkWarnings msgs; return x + TcFail (msg:msgs) -> do checkWarnings msgs; checkError msg newMeta :: Sigma -> TcM MetaId newMeta ty = TcM (\ms msgs -> -- cgit v1.2.3