git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Fix #1596, don't show type checker warnings in the event of an error
commitf8d6c4840dd123ee029d497ff2b26458c037dc17 authorPhil Freeman <paf31@cantab.net> dateWed 11 Nov 2015, 19:11 (11 years ago) parent381f73b
3 files changed+11−13
src/Language/PureScript/Errors.hs+7−9 src/Language/PureScript/Sugar/Names/Imports.hs+1−1 src/Language/PureScript/TypeChecker/Monad.hs+3−3
src/Language/PureScript/Errors.hs+7−9
@@ -32,7 +32,7 @@ import Control.Monad
3232import Control.Monad.Writer
3333import Control.Monad.Error.Class (MonadError(..))
3434import Control.Monad.Trans.State.Lazy
35−import Control.Arrow(first)
35+import Control.Arrow (first)
3636
3737import Language.PureScript.Crash
3838import Language.PureScript.AST
@@ -938,20 +938,18 @@ renderBox = unlines . map trimEnd . lines . Box.render
938938 where
939939 trimEnd = reverse . dropWhile (== ' ') . reverse
940940
941−-- |
942−-- Interpret multiple errors and warnings in a monad supporting errors and warnings
943−--
944−interpretMultipleErrorsAndWarnings :: (MonadError MultipleErrors m, MonadWriter MultipleErrors m) => (Either MultipleErrors a, MultipleErrors) -> m a
945−interpretMultipleErrorsAndWarnings (err, ws) = do
946− tell ws
947− either throwError return err
948−
949941-- |
950942-- Rethrow an error with a more detailed error message in the case of failure
951943--
952944rethrow :: (MonadError e m) => (e -> e) -> m a -> m a
953945rethrow f = flip catchError $ \e -> throwError (f e)
954946
947+reifyErrors :: (MonadError e m) => m a -> m (Either e a)
948+reifyErrors ma = catchError (fmap Right ma) (return . Left)
949+
950+reflectErrors :: (MonadError e m) => m (Either e a) -> m a
951+reflectErrors ma = ma >>= either throwError return
952+
955953warnAndRethrow :: (MonadError e m, MonadWriter e m) => (e -> e) -> m a -> m a
956954warnAndRethrow f = rethrow f . censor f
957955
src/Language/PureScript/Sugar/Names/Imports.hs+1−1
@@ -158,7 +158,7 @@ resolveImport currentModule importModule exps imps impQual =
158158 -- Import something explicitly
159159 importExplicit :: Imports -> DeclarationRef -> m Imports
160160 importExplicit imp (PositionedDeclarationRef pos _ r) =
161− rethrowWithPosition pos . warnWithPosition pos $ importExplicit imp r
161+ warnAndRethrowWithPosition pos $ importExplicit imp r
162162 importExplicit imp (ValueRef name) = do
163163 values' <- updateImports (importedValues imp) showIdent (exportedValues exps) name
164164 return $ imp { importedValues = values' }
src/Language/PureScript/TypeChecker/Monad.hs+3−3
@@ -211,21 +211,21 @@ freshDictionaryName = do
211211
212212-- | Run a computation in the substitution monad, generating a return value and the final substitution.
213213liftUnify ::
214− (MonadState CheckState m, MonadWriter MultipleErrors m) =>
214+ (MonadState CheckState m, MonadWriter MultipleErrors m, MonadError MultipleErrors m) =>
215215 m a ->
216216 m (a, Substitution)
217217liftUnify = liftUnifyWarnings (const id)
218218
219219-- | Run a computation in the substitution monad, generating a return value, the final substitution and updating warnings values.
220220liftUnifyWarnings ::
221− (MonadState CheckState m, MonadWriter MultipleErrors m) =>
221+ (MonadState CheckState m, MonadWriter MultipleErrors m, MonadError MultipleErrors m) =>
222222 (Substitution -> ErrorMessage -> ErrorMessage) ->
223223 m a ->
224224 m (a, Substitution)
225225liftUnifyWarnings replace ma = do
226226 orig <- get
227227 modify $ \st -> st { checkSubstitution = emptySubstitution }
228− (a, w) <- censor (const mempty) . listen $ ma
228+ (a, w) <- reflectErrors . censor (const mempty) . reifyErrors . listen $ ma
229229 subst <- gets checkSubstitution
230230 tell . onErrorMessages (replace subst) $ w
231231 modify $ \st -> st { checkSubstitution = checkSubstitution orig }