@@ -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
@@ -100,6 +99,7 @@ data SimpleErrorMessage
100 | CtorConflictsWithClass ProperName
99 | CtorConflictsWithClass ProperName
101 | ClassConflictsWithType ProperName
100 | ClassConflictsWithType ProperName
102 | ClassConflictsWithCtor ProperName
101 | ClassConflictsWithCtor ProperName
102+ | DuplicateModuleName ModuleName
103 | DuplicateClassExport ProperName
103 | DuplicateClassExport ProperName
104 | DuplicateValueExport Ident
104 | DuplicateValueExport Ident
105 | DuplicateTypeArgument String
105 | DuplicateTypeArgument String
@@ -145,6 +145,7 @@ data SimpleErrorMessage
145 | WildcardInferredType Type
145 | WildcardInferredType Type
146 | NotExhaustivePattern [[Binder]] Bool
146 | NotExhaustivePattern [[Binder]] Bool
147 | OverlappingPattern [[Binder]] Bool
147 | OverlappingPattern [[Binder]] Bool
148+ | IncompleteExhaustivityCheck
148 | ClassOperator ProperName Ident
149 | ClassOperator ProperName Ident
149 | MisleadingEmptyTypeImport ModuleName ProperName
150 | MisleadingEmptyTypeImport ModuleName ProperName
150 | ImportHidingModule ModuleName
151 | ImportHidingModule ModuleName
@@ -229,6 +230,7 @@ errorCode em = case unwrapErrorMessage em of
229 CtorConflictsWithClass{} -> "CtorConflictsWithClass"
230 CtorConflictsWithClass{} -> "CtorConflictsWithClass"
230 ClassConflictsWithType{} -> "ClassConflictsWithType"
231 ClassConflictsWithType{} -> "ClassConflictsWithType"
231 ClassConflictsWithCtor{} -> "ClassConflictsWithCtor"
232 ClassConflictsWithCtor{} -> "ClassConflictsWithCtor"
233+ DuplicateModuleName{} -> "DuplicateModuleName"
232 DuplicateClassExport{} -> "DuplicateClassExport"
234 DuplicateClassExport{} -> "DuplicateClassExport"
233 DuplicateValueExport{} -> "DuplicateValueExport"
235 DuplicateValueExport{} -> "DuplicateValueExport"
234 DuplicateTypeArgument{} -> "DuplicateTypeArgument"
236 DuplicateTypeArgument{} -> "DuplicateTypeArgument"
@@ -274,6 +276,7 @@ errorCode em = case unwrapErrorMessage em of
274 WildcardInferredType{} -> "WildcardInferredType"
276 WildcardInferredType{} -> "WildcardInferredType"
275 NotExhaustivePattern{} -> "NotExhaustivePattern"
277 NotExhaustivePattern{} -> "NotExhaustivePattern"
276 OverlappingPattern{} -> "OverlappingPattern"
278 OverlappingPattern{} -> "OverlappingPattern"
279+ IncompleteExhaustivityCheck{} -> "IncompleteExhaustivityCheck"
277 ClassOperator{} -> "ClassOperator"
280 ClassOperator{} -> "ClassOperator"
278 MisleadingEmptyTypeImport{} -> "MisleadingEmptyTypeImport"
281 MisleadingEmptyTypeImport{} -> "MisleadingEmptyTypeImport"
279 ImportHidingModule{} -> "ImportHidingModule"
282 ImportHidingModule{} -> "ImportHidingModule"
@@ -364,33 +367,33 @@ replaceUnknowns = everywhereOnTypesM replaceTypes
364onTypesInErrorMessageM :: (Applicative m) => (Type -> m Type) -> ErrorMessage -> m ErrorMessage
367onTypesInErrorMessageM :: (Applicative m) => (Type -> m Type) -> ErrorMessage -> m ErrorMessage
365onTypesInErrorMessageM f = g
368onTypesInErrorMessageM f = g
367− gSimple (InfiniteType t) = InfiniteType <$> (f t)
370+ gSimple (InfiniteType t) = InfiniteType <$> f t
368− gSimple (TypesDoNotUnify t1 t2) = TypesDoNotUnify <$> (f t1) <*> (f t2)
371+ gSimple (TypesDoNotUnify t1 t2) = TypesDoNotUnify <$> f t1 <*> f t2
369− gSimple (ConstrainedTypeUnified t1 t2) = ConstrainedTypeUnified <$> (f t1) <*> (f t2)
372+ gSimple (ConstrainedTypeUnified t1 t2) = ConstrainedTypeUnified <$> f t1 <*> f t2
370− gSimple (ExprDoesNotHaveType e t) = ExprDoesNotHaveType e <$> (f t)
373+ gSimple (ExprDoesNotHaveType e t) = ExprDoesNotHaveType e <$> f t
371− gSimple (PropertyIsMissing s t) = PropertyIsMissing s <$> (f t)
374+ gSimple (PropertyIsMissing s t) = PropertyIsMissing s <$> f t
372− gSimple (CannotApplyFunction t e) = CannotApplyFunction <$> f t <*> (pure e)
375+ gSimple (CannotApplyFunction t e) = CannotApplyFunction <$> f t <*> pure e
373 gSimple (InvalidInstanceHead t) = InvalidInstanceHead <$> f t
376 gSimple (InvalidInstanceHead t) = InvalidInstanceHead <$> f t
374 gSimple other = pure other
377 gSimple other = pure other
375− g (ErrorInSubsumption t1 t2 em) = ErrorInSubsumption <$> (f t1) <*> (f t2) <*> (g em)
378+ g (ErrorInSubsumption t1 t2 em) = ErrorInSubsumption <$> f t1 <*> f t2 <*> g em
376− g (ErrorUnifyingTypes t1 t2 e) = ErrorUnifyingTypes <$> (f t1) <*> (f t2) <*> (g e)
379+ g (ErrorUnifyingTypes t1 t2 e) = ErrorUnifyingTypes <$> f t1 <*> f t2 <*> g e
377− g (ErrorCheckingType e t em) = ErrorCheckingType e <$> (f t) <*> (g em)
380+ g (ErrorCheckingType e t em) = ErrorCheckingType e <$> f t <*> g em
378− g (ErrorCheckingKind t em) = ErrorCheckingKind <$> (f t) <*> g em
381+ g (ErrorCheckingKind t em) = ErrorCheckingKind <$> f t <*> g em
379− g (ErrorInApplication e1 t1 e2 em) = ErrorInApplication e1 <$> (f t1) <*> (pure e2) <*> (g em)
382+ g (ErrorInApplication e1 t1 e2 em) = ErrorInApplication e1 <$> f t1 <*> pure e2 <*> g em
380− g (NotYetDefined x e) = NotYetDefined x <$> (g e)
383+ g (NotYetDefined x e) = NotYetDefined x <$> g e
381− g (ErrorInExpression x e) = ErrorInExpression x <$> (g e)
384+ g (ErrorInExpression x e) = ErrorInExpression x <$> g e
382− g (ErrorInModule x e) = ErrorInModule x <$> (g e)
385+ g (ErrorInModule x e) = ErrorInModule x <$> g e
383− g (ErrorInInstance x y e) = ErrorInInstance x y <$> (g e)
386+ g (ErrorInInstance x y e) = ErrorInInstance x y <$> g e
384− g (ErrorInferringType x e) = ErrorInferringType x <$> (g e)
387+ g (ErrorInferringType x e) = ErrorInferringType x <$> g e
385− g (ErrorInDataConstructor x e) = ErrorInDataConstructor x <$> (g e)
388+ g (ErrorInDataConstructor x e) = ErrorInDataConstructor x <$> g e
386− g (ErrorInTypeConstructor x e) = ErrorInTypeConstructor x <$> (g e)
389+ g (ErrorInTypeConstructor x e) = ErrorInTypeConstructor x <$> g e
387− g (ErrorInBindingGroup x e) = ErrorInBindingGroup x <$> (g e)
390+ g (ErrorInBindingGroup x e) = ErrorInBindingGroup x <$> g e
388− g (ErrorInDataBindingGroup e) = ErrorInDataBindingGroup <$> (g e)
391+ g (ErrorInDataBindingGroup e) = ErrorInDataBindingGroup <$> g e
389− g (ErrorInTypeSynonym x e) = ErrorInTypeSynonym x <$> (g e)
392+ g (ErrorInTypeSynonym x e) = ErrorInTypeSynonym x <$> g e
390− g (ErrorInValueDeclaration x e) = ErrorInValueDeclaration x <$> (g e)
393+ g (ErrorInValueDeclaration x e) = ErrorInValueDeclaration x <$> g e
391− g (ErrorInTypeDeclaration x e) = ErrorInTypeDeclaration x <$> (g e)
394+ g (ErrorInTypeDeclaration x e) = ErrorInTypeDeclaration x <$> g e
392− g (ErrorInForeignImport x e) = ErrorInForeignImport x <$> (g e)
395+ g (ErrorInForeignImport x e) = ErrorInForeignImport x <$> g e
393− g (PositionedError x e) = PositionedError x <$> (g e)
396+ g (PositionedError x e) = PositionedError x <$> g e
394 g (SimpleErrorWrapper sem) = SimpleErrorWrapper <$> gSimple sem
397 g (SimpleErrorWrapper sem) = SimpleErrorWrapper <$> gSimple sem
@@ -524,6 +527,8 @@ prettyPrintSingleError full level e = prettyPrintErrorMessage <$> onTypesInError
524 line $ "Type class " ++ runProperName nm ++ " conflicts with type declaration of the same name"
527 line $ "Type class " ++ runProperName nm ++ " conflicts with type declaration of the same name"
525 goSimple (ClassConflictsWithCtor nm) =
528 goSimple (ClassConflictsWithCtor nm) =
526 line $ "Type class " ++ runProperName nm ++ " conflicts with data constructor declaration of the same name"
529 line $ "Type class " ++ runProperName nm ++ " conflicts with data constructor declaration of the same name"
530+ goSimple (DuplicateModuleName mn) =
531+ line $ "Module " ++ runModuleName mn ++ " has been defined multiple times."
527 goSimple (DuplicateClassExport nm) =
532 goSimple (DuplicateClassExport nm) =
528 line $ "Duplicate export declaration for type class " ++ runProperName nm
533 line $ "Duplicate export declaration for type class " ++ runProperName nm
529 goSimple (DuplicateValueExport nm) =
534 goSimple (DuplicateValueExport nm) =
@@ -662,6 +667,10 @@ prettyPrintSingleError full level e = prettyPrintErrorMessage <$> onTypesInError
662 , Box.hsep 1 Box.left (map (paras . map (line . prettyPrintBinderAtom)) (transpose bs))
667 , Box.hsep 1 Box.left (map (paras . map (line . prettyPrintBinderAtom)) (transpose bs))
664 [ line "..." | not b ]
669 [ line "..." | not b ]
670+ goSimple IncompleteExhaustivityCheck =
671+ paras [ line "An exhaustivity check was abandoned due to too many possible cases."
672+ , line "You may want to decomposing your data types into smaller types."
665 go (NotYetDefined names err) =
674 go (NotYetDefined names err) =
666 paras [ line $ "The following are not yet defined here: " ++ intercalate ", " (map showIdent names) ++ ":"
675 paras [ line $ "The following are not yet defined here: " ++ intercalate ", " (map showIdent names) ++ ":"
667 , indent $ go err
676 , indent $ go err
@@ -732,7 +741,7 @@ prettyPrintSingleError full level e = prettyPrintErrorMessage <$> onTypesInError
734 go (ErrorInDataBindingGroup err) =
743 go (ErrorInDataBindingGroup err) =
735− paras [ lineWithLevel $ "in data binding group:"
744+ paras [ lineWithLevel "in data binding group:"
738 go (ErrorInTypeSynonym name err) =
747 go (ErrorInTypeSynonym name err) =
@@ -851,7 +860,7 @@ prettyPrintMultipleErrorsWith level intro _ full (MultipleErrors [e]) = do
853prettyPrintMultipleErrorsWith level _ intro full (MultipleErrors es) = do
862prettyPrintMultipleErrorsWith level _ intro full (MultipleErrors es) = do
854− result <- forM es $ (liftM $ Box.moveRight 2) . prettyPrintSingleError full level
863+ result <- forM es $ liftM (Box.moveRight 2) . prettyPrintSingleError full level
856 Box.vcat Box.left [ Box.text intro
865 Box.vcat Box.left [ Box.text intro
857 , Box.vsep 1 Box.left result
866 , Box.vsep 1 Box.left result
@@ -859,7 +868,7 @@ prettyPrintMultipleErrorsWith level _ intro full (MultipleErrors es) = do
860-- | Pretty print a Parsec ParseError as a Box
869-- | Pretty print a Parsec ParseError as a Box
861prettyPrintParseError :: P.ParseError -> Box.Box
870prettyPrintParseError :: P.ParseError -> Box.Box
862−prettyPrintParseError = (prettyPrintParseErrorMessages "or" "unknown parse error" "expecting" "unexpected" "end of input") . PE.errorMessages
871+prettyPrintParseError = prettyPrintParseErrorMessages "or" "unknown parse error" "expecting" "unexpected" "end of input" . PE.errorMessages
865-- Pretty print ParseError detail messages.
874-- Pretty print ParseError detail messages.
@@ -872,9 +881,9 @@ prettyPrintParseErrorMessages msgOr msgUnknown msgExpecting msgUnExpected msgEnd
872 | otherwise = Box.vcat Box.left $ map Box.text $ clean [showSysUnExpect,showUnExpect,showExpect,showMessages]
881 | otherwise = Box.vcat Box.left $ map Box.text $ clean [showSysUnExpect,showUnExpect,showExpect,showMessages]
875− (sysUnExpect,msgs1) = span ((SysUnExpect "") ==) msgs
884+ (sysUnExpect,msgs1) = span (SysUnExpect "" ==) msgs
876− (unExpect,msgs2) = span ((UnExpect "") ==) msgs1
885+ (unExpect,msgs2) = span (UnExpect "" ==) msgs1
877− (expect,messages) = span ((Expect "") ==) msgs2
886+ (expect,messages) = span (Expect "" ==) msgs2
879 showExpect = showMany msgExpecting expect
888 showExpect = showMany msgExpecting expect
880 showUnExpect = showMany msgUnExpected unExpect
889 showUnExpect = showMany msgUnExpected unExpect
@@ -922,7 +931,7 @@ renderBox = unlines . map trimEnd . lines . Box.render
922interpretMultipleErrorsAndWarnings :: (MonadError MultipleErrors m, MonadWriter MultipleErrors m) => (Either MultipleErrors a, MultipleErrors) -> m a
931interpretMultipleErrorsAndWarnings :: (MonadError MultipleErrors m, MonadWriter MultipleErrors m) => (Either MultipleErrors a, MultipleErrors) -> m a
923interpretMultipleErrorsAndWarnings (err, ws) = do
932interpretMultipleErrorsAndWarnings (err, ws) = do
925− either throwError return $ err
934+ either throwError return err
928-- Rethrow an error with a more detailed error message in the case of failure
937-- Rethrow an error with a more detailed error message in the case of failure