@@ -20,7 +20,7 @@
20module Language.PureScript.Errors where
20module Language.PureScript.Errors where
22import Data.Either (lefts, rights)
22import Data.Either (lefts, rights)
23−import Data.List (intercalate, transpose)
23+import Data.List (intercalate, transpose, nub)
24import Data.Function (on)
24import Data.Function (on)
25#if __GLASGOW_HASKELL__ < 710
25#if __GLASGOW_HASKELL__ < 710
26import Data.Foldable (fold, foldMap)
26import Data.Foldable (fold, foldMap)
@@ -52,7 +52,6 @@ import qualified Text.PrettyPrint.Boxes as Box
52import qualified Text.Parsec as P
52import qualified Text.Parsec as P
53import qualified Text.Parsec.Error as PE
53import qualified Text.Parsec.Error as PE
54import Text.Parsec.Error (Message(..))
54import Text.Parsec.Error (Message(..))
55−import Data.List (nub)
58-- A type of error messages
57-- A type of error messages
@@ -366,33 +365,33 @@ replaceUnknowns = everywhereOnTypesM replaceTypes
366onTypesInErrorMessageM :: (Applicative m) => (Type -> m Type) -> ErrorMessage -> m ErrorMessage
365onTypesInErrorMessageM :: (Applicative m) => (Type -> m Type) -> ErrorMessage -> m ErrorMessage
367onTypesInErrorMessageM f = g
366onTypesInErrorMessageM f = g
369− gSimple (InfiniteType t) = InfiniteType <$> (f t)
368+ gSimple (InfiniteType t) = InfiniteType <$> f t
370− gSimple (TypesDoNotUnify t1 t2) = TypesDoNotUnify <$> (f t1) <*> (f t2)
369+ gSimple (TypesDoNotUnify t1 t2) = TypesDoNotUnify <$> f t1 <*> f t2
371− gSimple (ConstrainedTypeUnified t1 t2) = ConstrainedTypeUnified <$> (f t1) <*> (f t2)
370+ gSimple (ConstrainedTypeUnified t1 t2) = ConstrainedTypeUnified <$> f t1 <*> f t2
372− gSimple (ExprDoesNotHaveType e t) = ExprDoesNotHaveType e <$> (f t)
371+ gSimple (ExprDoesNotHaveType e t) = ExprDoesNotHaveType e <$> f t
373− gSimple (PropertyIsMissing s t) = PropertyIsMissing s <$> (f t)
372+ gSimple (PropertyIsMissing s t) = PropertyIsMissing s <$> f t
374− gSimple (CannotApplyFunction t e) = CannotApplyFunction <$> f t <*> (pure e)
373+ gSimple (CannotApplyFunction t e) = CannotApplyFunction <$> f t <*> pure e
375 gSimple (InvalidInstanceHead t) = InvalidInstanceHead <$> f t
374 gSimple (InvalidInstanceHead t) = InvalidInstanceHead <$> f t
376 gSimple other = pure other
375 gSimple other = pure other
377− g (ErrorInSubsumption t1 t2 em) = ErrorInSubsumption <$> (f t1) <*> (f t2) <*> (g em)
376+ g (ErrorInSubsumption t1 t2 em) = ErrorInSubsumption <$> f t1 <*> f t2 <*> g em
378− g (ErrorUnifyingTypes t1 t2 e) = ErrorUnifyingTypes <$> (f t1) <*> (f t2) <*> (g e)
377+ g (ErrorUnifyingTypes t1 t2 e) = ErrorUnifyingTypes <$> f t1 <*> f t2 <*> g e
379− g (ErrorCheckingType e t em) = ErrorCheckingType e <$> (f t) <*> (g em)
378+ g (ErrorCheckingType e t em) = ErrorCheckingType e <$> f t <*> g em
380− g (ErrorCheckingKind t em) = ErrorCheckingKind <$> (f t) <*> g em
379+ g (ErrorCheckingKind t em) = ErrorCheckingKind <$> f t <*> g em
381− g (ErrorInApplication e1 t1 e2 em) = ErrorInApplication e1 <$> (f t1) <*> (pure e2) <*> (g em)
380+ g (ErrorInApplication e1 t1 e2 em) = ErrorInApplication e1 <$> f t1 <*> pure e2 <*> g em
382− g (NotYetDefined x e) = NotYetDefined x <$> (g e)
381+ g (NotYetDefined x e) = NotYetDefined x <$> g e
383− g (ErrorInExpression x e) = ErrorInExpression x <$> (g e)
382+ g (ErrorInExpression x e) = ErrorInExpression x <$> g e
384− g (ErrorInModule x e) = ErrorInModule x <$> (g e)
383+ g (ErrorInModule x e) = ErrorInModule x <$> g e
385− g (ErrorInInstance x y e) = ErrorInInstance x y <$> (g e)
384+ g (ErrorInInstance x y e) = ErrorInInstance x y <$> g e
386− g (ErrorInferringType x e) = ErrorInferringType x <$> (g e)
385+ g (ErrorInferringType x e) = ErrorInferringType x <$> g e
387− g (ErrorInDataConstructor x e) = ErrorInDataConstructor x <$> (g e)
386+ g (ErrorInDataConstructor x e) = ErrorInDataConstructor x <$> g e
388− g (ErrorInTypeConstructor x e) = ErrorInTypeConstructor x <$> (g e)
387+ g (ErrorInTypeConstructor x e) = ErrorInTypeConstructor x <$> g e
389− g (ErrorInBindingGroup x e) = ErrorInBindingGroup x <$> (g e)
388+ g (ErrorInBindingGroup x e) = ErrorInBindingGroup x <$> g e
390− g (ErrorInDataBindingGroup e) = ErrorInDataBindingGroup <$> (g e)
389+ g (ErrorInDataBindingGroup e) = ErrorInDataBindingGroup <$> g e
391− g (ErrorInTypeSynonym x e) = ErrorInTypeSynonym x <$> (g e)
390+ g (ErrorInTypeSynonym x e) = ErrorInTypeSynonym x <$> g e
392− g (ErrorInValueDeclaration x e) = ErrorInValueDeclaration x <$> (g e)
391+ g (ErrorInValueDeclaration x e) = ErrorInValueDeclaration x <$> g e
393− g (ErrorInTypeDeclaration x e) = ErrorInTypeDeclaration x <$> (g e)
392+ g (ErrorInTypeDeclaration x e) = ErrorInTypeDeclaration x <$> g e
394− g (ErrorInForeignImport x e) = ErrorInForeignImport x <$> (g e)
393+ g (ErrorInForeignImport x e) = ErrorInForeignImport x <$> g e
395− g (PositionedError x e) = PositionedError x <$> (g e)
394+ g (PositionedError x e) = PositionedError x <$> g e
396 g (SimpleErrorWrapper sem) = SimpleErrorWrapper <$> gSimple sem
395 g (SimpleErrorWrapper sem) = SimpleErrorWrapper <$> gSimple sem
@@ -738,7 +737,7 @@ prettyPrintSingleError full level e = prettyPrintErrorMessage <$> onTypesInError
740 go (ErrorInDataBindingGroup err) =
739 go (ErrorInDataBindingGroup err) =
741− paras [ lineWithLevel $ "in data binding group:"
740+ paras [ lineWithLevel "in data binding group:"
744 go (ErrorInTypeSynonym name err) =
743 go (ErrorInTypeSynonym name err) =
@@ -857,7 +856,7 @@ prettyPrintMultipleErrorsWith level intro _ full (MultipleErrors [e]) = do
859prettyPrintMultipleErrorsWith level _ intro full (MultipleErrors es) = do
858prettyPrintMultipleErrorsWith level _ intro full (MultipleErrors es) = do
860− result <- forM es $ (liftM $ Box.moveRight 2) . prettyPrintSingleError full level
859+ result <- forM es $ liftM (Box.moveRight 2) . prettyPrintSingleError full level
862 Box.vcat Box.left [ Box.text intro
861 Box.vcat Box.left [ Box.text intro
863 , Box.vsep 1 Box.left result
862 , Box.vsep 1 Box.left result
@@ -865,7 +864,7 @@ prettyPrintMultipleErrorsWith level _ intro full (MultipleErrors es) = do
866-- | Pretty print a Parsec ParseError as a Box
865-- | Pretty print a Parsec ParseError as a Box
867prettyPrintParseError :: P.ParseError -> Box.Box
866prettyPrintParseError :: P.ParseError -> Box.Box
868−prettyPrintParseError = (prettyPrintParseErrorMessages "or" "unknown parse error" "expecting" "unexpected" "end of input") . PE.errorMessages
867+prettyPrintParseError = prettyPrintParseErrorMessages "or" "unknown parse error" "expecting" "unexpected" "end of input" . PE.errorMessages
871-- Pretty print ParseError detail messages.
870-- Pretty print ParseError detail messages.
@@ -878,9 +877,9 @@ prettyPrintParseErrorMessages msgOr msgUnknown msgExpecting msgUnExpected msgEnd
878 | otherwise = Box.vcat Box.left $ map Box.text $ clean [showSysUnExpect,showUnExpect,showExpect,showMessages]
877 | otherwise = Box.vcat Box.left $ map Box.text $ clean [showSysUnExpect,showUnExpect,showExpect,showMessages]
881− (sysUnExpect,msgs1) = span ((SysUnExpect "") ==) msgs
880+ (sysUnExpect,msgs1) = span (SysUnExpect "" ==) msgs
882− (unExpect,msgs2) = span ((UnExpect "") ==) msgs1
881+ (unExpect,msgs2) = span (UnExpect "" ==) msgs1
883− (expect,messages) = span ((Expect "") ==) msgs2
882+ (expect,messages) = span (Expect "" ==) msgs2
885 showExpect = showMany msgExpecting expect
884 showExpect = showMany msgExpecting expect
886 showUnExpect = showMany msgUnExpected unExpect
885 showUnExpect = showMany msgUnExpected unExpect
@@ -928,7 +927,7 @@ renderBox = unlines . map trimEnd . lines . Box.render
928interpretMultipleErrorsAndWarnings :: (MonadError MultipleErrors m, MonadWriter MultipleErrors m) => (Either MultipleErrors a, MultipleErrors) -> m a
927interpretMultipleErrorsAndWarnings :: (MonadError MultipleErrors m, MonadWriter MultipleErrors m) => (Either MultipleErrors a, MultipleErrors) -> m a
929interpretMultipleErrorsAndWarnings (err, ws) = do
928interpretMultipleErrorsAndWarnings (err, ws) = do
931− either throwError return $ err
930+ either throwError return err
934-- Rethrow an error with a more detailed error message in the case of failure
933-- Rethrow an error with a more detailed error message in the case of failure