@@ -20,7 +20,7 @@
2020module Language.PureScript.Errors where
2121
2222import Data.Either (lefts, rights)
23−import Data.List (intercalate, transpose)
23+import Data.List (intercalate, transpose, nub)
2424import Data.Function (on)
2525#if __GLASGOW_HASKELL__ < 710
2626import Data.Foldable (fold, foldMap)
@@ -52,7 +52,6 @@ import qualified Text.PrettyPrint.Boxes as Box
5252import qualified Text.Parsec as P
5353import qualified Text.Parsec.Error as PE
5454import Text.Parsec.Error (Message(..))
55−import Data.List (nub)
5655
5756-- |
5857-- A type of error messages
@@ -366,33 +365,33 @@ replaceUnknowns = everywhereOnTypesM replaceTypes
366365onTypesInErrorMessageM :: (Applicative m) => (Type -> m Type) -> ErrorMessage -> m ErrorMessage
367366onTypesInErrorMessageM f = g
368367 where
369− gSimple (InfiniteType t) = InfiniteType <$> (f t)
370− gSimple (TypesDoNotUnify t1 t2) = TypesDoNotUnify <$> (f t1) <*> (f t2)
371− gSimple (ConstrainedTypeUnified t1 t2) = ConstrainedTypeUnified <$> (f t1) <*> (f t2)
372− gSimple (ExprDoesNotHaveType e t) = ExprDoesNotHaveType e <$> (f t)
373− gSimple (PropertyIsMissing s t) = PropertyIsMissing s <$> (f t)
374− gSimple (CannotApplyFunction t e) = CannotApplyFunction <$> f t <*> (pure e)
368+ gSimple (InfiniteType t) = InfiniteType <$> f t
369+ gSimple (TypesDoNotUnify t1 t2) = TypesDoNotUnify <$> f t1 <*> f t2
370+ gSimple (ConstrainedTypeUnified t1 t2) = ConstrainedTypeUnified <$> f t1 <*> f t2
371+ gSimple (ExprDoesNotHaveType e t) = ExprDoesNotHaveType e <$> f t
372+ gSimple (PropertyIsMissing s t) = PropertyIsMissing s <$> f t
373+ gSimple (CannotApplyFunction t e) = CannotApplyFunction <$> f t <*> pure e
375374 gSimple (InvalidInstanceHead t) = InvalidInstanceHead <$> f t
376375 gSimple other = pure other
377− 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)
379− g (ErrorCheckingType e t em) = ErrorCheckingType e <$> (f t) <*> (g em)
380− g (ErrorCheckingKind t em) = ErrorCheckingKind <$> (f t) <*> g em
381− g (ErrorInApplication e1 t1 e2 em) = ErrorInApplication e1 <$> (f t1) <*> (pure e2) <*> (g em)
382− g (NotYetDefined x e) = NotYetDefined x <$> (g e)
383− g (ErrorInExpression x e) = ErrorInExpression x <$> (g e)
384− g (ErrorInModule x e) = ErrorInModule x <$> (g e)
385− g (ErrorInInstance x y e) = ErrorInInstance x y <$> (g e)
386− g (ErrorInferringType x e) = ErrorInferringType x <$> (g e)
387− g (ErrorInDataConstructor x e) = ErrorInDataConstructor x <$> (g e)
388− g (ErrorInTypeConstructor x e) = ErrorInTypeConstructor x <$> (g e)
389− g (ErrorInBindingGroup x e) = ErrorInBindingGroup x <$> (g e)
390− g (ErrorInDataBindingGroup e) = ErrorInDataBindingGroup <$> (g e)
391− g (ErrorInTypeSynonym x e) = ErrorInTypeSynonym x <$> (g e)
392− g (ErrorInValueDeclaration x e) = ErrorInValueDeclaration x <$> (g e)
393− g (ErrorInTypeDeclaration x e) = ErrorInTypeDeclaration x <$> (g e)
394− g (ErrorInForeignImport x e) = ErrorInForeignImport x <$> (g e)
395− g (PositionedError x e) = PositionedError x <$> (g e)
376+ g (ErrorInSubsumption t1 t2 em) = ErrorInSubsumption <$> f t1 <*> f t2 <*> g em
377+ g (ErrorUnifyingTypes t1 t2 e) = ErrorUnifyingTypes <$> f t1 <*> f t2 <*> g e
378+ g (ErrorCheckingType e t em) = ErrorCheckingType e <$> f t <*> g em
379+ g (ErrorCheckingKind t em) = ErrorCheckingKind <$> f t <*> g em
380+ g (ErrorInApplication e1 t1 e2 em) = ErrorInApplication e1 <$> f t1 <*> pure e2 <*> g em
381+ g (NotYetDefined x e) = NotYetDefined x <$> g e
382+ g (ErrorInExpression x e) = ErrorInExpression x <$> g e
383+ g (ErrorInModule x e) = ErrorInModule x <$> g e
384+ g (ErrorInInstance x y e) = ErrorInInstance x y <$> g e
385+ g (ErrorInferringType x e) = ErrorInferringType x <$> g e
386+ g (ErrorInDataConstructor x e) = ErrorInDataConstructor x <$> g e
387+ g (ErrorInTypeConstructor x e) = ErrorInTypeConstructor x <$> g e
388+ g (ErrorInBindingGroup x e) = ErrorInBindingGroup x <$> g e
389+ g (ErrorInDataBindingGroup e) = ErrorInDataBindingGroup <$> g e
390+ g (ErrorInTypeSynonym x e) = ErrorInTypeSynonym x <$> g e
391+ g (ErrorInValueDeclaration x e) = ErrorInValueDeclaration x <$> g e
392+ g (ErrorInTypeDeclaration x e) = ErrorInTypeDeclaration x <$> g e
393+ g (ErrorInForeignImport x e) = ErrorInForeignImport x <$> g e
394+ g (PositionedError x e) = PositionedError x <$> g e
396395 g (SimpleErrorWrapper sem) = SimpleErrorWrapper <$> gSimple sem
397396
398397-- |
@@ -738,7 +737,7 @@ prettyPrintSingleError full level e = prettyPrintErrorMessage <$> onTypesInError
738737 , go err
739738 ]
740739 go (ErrorInDataBindingGroup err) =
741− paras [ lineWithLevel $ "in data binding group:"
740+ paras [ lineWithLevel "in data binding group:"
742741 , go err
743742 ]
744743 go (ErrorInTypeSynonym name err) =
@@ -857,7 +856,7 @@ prettyPrintMultipleErrorsWith level intro _ full (MultipleErrors [e]) = do
857856 , result
858857 ]
859858prettyPrintMultipleErrorsWith 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
861860 return $
862861 Box.vcat Box.left [ Box.text intro
863862 , Box.vsep 1 Box.left result
@@ -865,7 +864,7 @@ prettyPrintMultipleErrorsWith level _ intro full (MultipleErrors es) = do
865864
866865-- | Pretty print a Parsec ParseError as a Box
867866prettyPrintParseError :: 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
869868
870869-- |
871870-- Pretty print ParseError detail messages.
@@ -878,9 +877,9 @@ prettyPrintParseErrorMessages msgOr msgUnknown msgExpecting msgUnExpected msgEnd
878877 | otherwise = Box.vcat Box.left $ map Box.text $ clean [showSysUnExpect,showUnExpect,showExpect,showMessages]
879878
880879 where
881− (sysUnExpect,msgs1) = span ((SysUnExpect "") ==) msgs
882− (unExpect,msgs2) = span ((UnExpect "") ==) msgs1
883− (expect,messages) = span ((Expect "") ==) msgs2
880+ (sysUnExpect,msgs1) = span (SysUnExpect "" ==) msgs
881+ (unExpect,msgs2) = span (UnExpect "" ==) msgs1
882+ (expect,messages) = span (Expect "" ==) msgs2
884883
885884 showExpect = showMany msgExpecting expect
886885 showUnExpect = showMany msgUnExpected unExpect
@@ -928,7 +927,7 @@ renderBox = unlines . map trimEnd . lines . Box.render
928927interpretMultipleErrorsAndWarnings :: (MonadError MultipleErrors m, MonadWriter MultipleErrors m) => (Either MultipleErrors a, MultipleErrors) -> m a
929928interpretMultipleErrorsAndWarnings (err, ws) = do
930929 tell ws
931− either throwError return $ err
930+ either throwError return err
932931
933932-- |
934933-- Rethrow an error with a more detailed error message in the case of failure