summaryrefslogtreecommitdiff
path: root/src/compiler/GF/Infra/CheckM.hs
diff options
context:
space:
mode:
authorhallgren <hallgren@chalmers.se>2012-06-26 14:46:18 +0000
committerhallgren <hallgren@chalmers.se>2012-06-26 14:46:18 +0000
commitb094274c0e6e0218977a65821066a3970254810a (patch)
treee5cdbb20a5fb276aec6e081802c163fcb213ad91 /src/compiler/GF/Infra/CheckM.hs
parenta38efe70c6aa340242cb25c3b8fd2845f98b1bb8 (diff)
Report many type errors instead of stopping after the first one
In GF.Compile.CheckGrammar, use a new topological sorting function that groups independent judgements, allowing them all to be checked before continuing or reporting errors.
Diffstat (limited to 'src/compiler/GF/Infra/CheckM.hs')
-rw-r--r--src/compiler/GF/Infra/CheckM.hs16
1 files changed, 14 insertions, 2 deletions
diff --git a/src/compiler/GF/Infra/CheckM.hs b/src/compiler/GF/Infra/CheckM.hs
index ea07d06c4..940701a1d 100644
--- a/src/compiler/GF/Infra/CheckM.hs
+++ b/src/compiler/GF/Infra/CheckM.hs
@@ -16,7 +16,7 @@ module GF.Infra.CheckM
(Check, CheckResult, Message, runCheck,
checkError, checkCond, checkWarn, checkWarnings, checkAccumError,
checkErr, checkIn, checkMap, checkMapRecover,
- accumulateError
+ accumulateError, commitCheck
) where
import GF.Data.Operations
@@ -75,6 +75,18 @@ accumulateError :: (a -> Check a) -> a -> Check a
accumulateError chk a =
handle' (chk a) $ \ msg -> do checkAccumError msg; return a
+-- | Turn accumulated errors into a fatal error
+commitCheck :: Check a -> Check a
+commitCheck c =
+ Check $ \ ctxt msgs0@(es0,ws0) ->
+ case unCheck c ctxt ([],[]) of
+ (([],ws),Success v) -> ((es0,ws++ws0),Success v)
+ (msgs ,Success _) -> bad msgs0 msgs
+ ((es,ws),Fail e) -> bad msgs0 ((e:es),ws)
+ where
+ bad (es0,ws0) (es,ws) = ((es0,ws++ws0),Fail (list es))
+ list = vcat . reverse
+
-- | Run an error check, report errors and warnings
runCheck :: Check a -> Err (a,String)
runCheck c =
@@ -92,7 +104,7 @@ checkMap f map = do xs <- mapM (\(k,v) -> do v <- f k v
return (Map.fromAscList xs)
checkMapRecover :: (Ord a) => (a -> b -> Check b) -> Map.Map a b -> Check (Map.Map a b)
-checkMapRecover f mp = checkMap f' mp
+checkMapRecover f mp = commitCheck (checkMap f' mp)
where f' key info = accumulateError (f key) info
{-
checkMapRecover f mp = do