@@ -272,6 +272,9 @@ data LabelType = TypeLabel | SkolemLabel String deriving (Show, Eq, Ord)
272-- | A map from rigid type variable name/unknown variable pairs to new variables.
272-- | A map from rigid type variable name/unknown variable pairs to new variables.
273type UnknownMap = M.Map (LabelType, Unknown) Unknown
273type UnknownMap = M.Map (LabelType, Unknown) Unknown
275+-- | How critical the issue is
276+data Level = Error | Warning deriving Show
276-- Extract nested error messages from wrapper errors
279-- Extract nested error messages from wrapper errors
@@ -344,8 +347,8 @@ onTypesInErrorMessageM f = g
345-- Pretty print a single error, simplifying if necessary
348-- Pretty print a single error, simplifying if necessary
347−prettyPrintSingleError :: Bool -> ErrorMessage -> State UnknownMap Box.Box
350+prettyPrintSingleError :: Bool -> Level -> ErrorMessage -> State UnknownMap Box.Box
348−prettyPrintSingleError full e = prettyPrintErrorMessage <$> onTypesInErrorMessageM replaceUnknowns (if full then e else simplifyErrorMessage e)
351+prettyPrintSingleError full level e = prettyPrintErrorMessage <$> onTypesInErrorMessageM replaceUnknowns (if full then e else simplifyErrorMessage e)
351 -- Pretty print an ErrorMessage
354 -- Pretty print an ErrorMessage
@@ -373,7 +376,7 @@ prettyPrintSingleError full e = prettyPrintErrorMessage <$> onTypesInErrorMessag
373 , indent . line $ path
376 , indent . line $ path
375 goSimple (ErrorParsingExterns err) =
378 goSimple (ErrorParsingExterns err) =
376− paras [ line "Error parsing externs files: "
379+ paras [ lineWithLevel "parsing externs files: "
377 , indent . line . show $ err
380 , indent . line . show $ err
379 goSimple (ErrorParsingFFIModule path) =
382 goSimple (ErrorParsingFFIModule path) =
@@ -561,51 +564,51 @@ prettyPrintSingleError full e = prettyPrintErrorMessage <$> onTypesInErrorMessag
561 , indent $ go err
564 , indent $ go err
563 go (ErrorUnifyingTypes t1 t2 err) =
566 go (ErrorUnifyingTypes t1 t2 err) =
564− paras [ line "Error unifying type "
567+ paras [ lineWithLevel "unifying type "
565 , indent $ line $ prettyPrintType t1
568 , indent $ line $ prettyPrintType t1
566 , line "with type"
569 , line "with type"
567 , indent $ line $ prettyPrintType t2
570 , indent $ line $ prettyPrintType t2
570 go (ErrorInExpression expr err) =
573 go (ErrorInExpression expr err) =
571− paras [ line "Error in expression:"
574+ paras [ lineWithLevel "in expression:"
572 , indent $ line $ prettyPrintValue expr
575 , indent $ line $ prettyPrintValue expr
575 go (ErrorInModule mn err) =
578 go (ErrorInModule mn err) =
576− paras [ line $ "Error in module " ++ show mn ++ ":"
579+ paras [ lineWithLevel $ "in module " ++ show mn ++ ":"
579 go (ErrorInSubsumption t1 t2 err) =
582 go (ErrorInSubsumption t1 t2 err) =
580− paras [ line "Error checking that type "
583+ paras [ lineWithLevel "checking that type "
581 , indent $ line $ prettyPrintType t1
584 , indent $ line $ prettyPrintType t1
582 , line "subsumes type"
585 , line "subsumes type"
583 , indent $ line $ prettyPrintType t2
586 , indent $ line $ prettyPrintType t2
586 go (ErrorInInstance name ts err) =
589 go (ErrorInInstance name ts err) =
587− paras [ line $ "Error in type class instance " ++ show name ++ " " ++ unwords (map prettyPrintTypeAtom ts) ++ ":"
590+ paras [ lineWithLevel $ "in type class instance " ++ show name ++ " " ++ unwords (map prettyPrintTypeAtom ts) ++ ":"
590 go (ErrorCheckingKind ty err) =
593 go (ErrorCheckingKind ty err) =
591− paras [ line "Error checking kind of type "
594+ paras [ lineWithLevel "checking kind of type "
592 , indent $ line $ prettyPrintType ty
595 , indent $ line $ prettyPrintType ty
595 go (ErrorInferringType expr err) =
598 go (ErrorInferringType expr err) =
596− paras [ line "Error inferring type of value "
599+ paras [ lineWithLevel "inferring type of value "
597 , indent $ line $ prettyPrintValue expr
600 , indent $ line $ prettyPrintValue expr
600 go (ErrorCheckingType expr ty err) =
603 go (ErrorCheckingType expr ty err) =
601− paras [ line "Error checking that value "
604+ paras [ lineWithLevel "checking that value "
602 , indent $ line $ prettyPrintValue expr
605 , indent $ line $ prettyPrintValue expr
603 , line "has type"
606 , line "has type"
604 , indent $ line $ prettyPrintType ty
607 , indent $ line $ prettyPrintType ty
607 go (ErrorInApplication f t a err) =
610 go (ErrorInApplication f t a err) =
608− paras [ line "Error applying function"
611+ paras [ lineWithLevel "applying function"
609 , indent $ line $ prettyPrintValue f
612 , indent $ line $ prettyPrintValue f
610 , line "of type"
613 , line "of type"
611 , indent $ line $ prettyPrintType t
614 , indent $ line $ prettyPrintType t
@@ -614,35 +617,35 @@ prettyPrintSingleError full e = prettyPrintErrorMessage <$> onTypesInErrorMessag
616 go (ErrorInDataConstructor nm err) =
619 go (ErrorInDataConstructor nm err) =
617− paras [ line $ "Error in data constructor " ++ show nm ++ ":"
620+ paras [ lineWithLevel $ "in data constructor " ++ show nm ++ ":"
620 go (ErrorInTypeConstructor nm err) =
623 go (ErrorInTypeConstructor nm err) =
621− paras [ line $ "Error in type constructor " ++ show nm ++ ":"
624+ paras [ lineWithLevel $ "in type constructor " ++ show nm ++ ":"
624 go (ErrorInBindingGroup nms err) =
627 go (ErrorInBindingGroup nms err) =
625− paras [ line $ "Error in binding group " ++ intercalate ", " (map show nms) ++ ":"
628+ paras [ lineWithLevel $ "in binding group " ++ intercalate ", " (map show nms) ++ ":"
628 go (ErrorInDataBindingGroup err) =
631 go (ErrorInDataBindingGroup err) =
629− paras [ line $ "Error in data binding group:"
632+ paras [ lineWithLevel $ "in data binding group:"
632 go (ErrorInTypeSynonym name err) =
635 go (ErrorInTypeSynonym name err) =
633− paras [ line $ "Error in type synonym " ++ show name ++ ":"
636+ paras [ lineWithLevel $ "in type synonym " ++ show name ++ ":"
636 go (ErrorInValueDeclaration n err) =
639 go (ErrorInValueDeclaration n err) =
637− paras [ line $ "Error in value declaration " ++ show n ++ ":"
640+ paras [ lineWithLevel $ "in value declaration " ++ show n ++ ":"
640 go (ErrorInForeignImport nm err) =
643 go (ErrorInForeignImport nm err) =
641− paras [ line $ "Error in foreign import " ++ show nm ++ ":"
644+ paras [ lineWithLevel $ "in foreign import " ++ show nm ++ ":"
644 go (PositionedError srcSpan err) =
647 go (PositionedError srcSpan err) =
645− paras [ line $ "Error at " ++ displaySourceSpan srcSpan ++ ":"
648+ paras [ lineWithLevel $ "at " ++ displaySourceSpan srcSpan ++ ":"
646 , indent $ go err
649 , indent $ go err
648 go (SimpleErrorWrapper sem) = goSimple sem
651 go (SimpleErrorWrapper sem) = goSimple sem
@@ -650,6 +653,9 @@ prettyPrintSingleError full e = prettyPrintErrorMessage <$> onTypesInErrorMessag
650 line :: String -> Box.Box
653 line :: String -> Box.Box
651 line = Box.text
654 line = Box.text
656+ lineWithLevel :: String -> Box.Box
657+ lineWithLevel text = line $ show level ++ " " ++ text
653 suggestions :: ErrorMessage -> [Box.Box]
659 suggestions :: ErrorMessage -> [Box.Box]
654 suggestions = suggestions' . unwrapErrorMessage
660 suggestions = suggestions' . unwrapErrorMessage
@@ -727,23 +733,23 @@ prettyPrintSingleError full e = prettyPrintErrorMessage <$> onTypesInErrorMessag
727-- Pretty print multiple errors
733-- Pretty print multiple errors
729prettyPrintMultipleErrors :: Bool -> MultipleErrors -> String
735prettyPrintMultipleErrors :: Bool -> MultipleErrors -> String
730−prettyPrintMultipleErrors full = flip evalState M.empty . prettyPrintMultipleErrorsWith "Error:" "Multiple errors:" full
736+prettyPrintMultipleErrors full = flip evalState M.empty . prettyPrintMultipleErrorsWith Error "Error:" "Multiple errors:" full
733-- Pretty print multiple warnings
739-- Pretty print multiple warnings
735prettyPrintMultipleWarnings :: Bool -> MultipleErrors -> String
741prettyPrintMultipleWarnings :: Bool -> MultipleErrors -> String
736−prettyPrintMultipleWarnings full = flip evalState M.empty . prettyPrintMultipleErrorsWith "Warning:" "Multiple warnings:" full
742+prettyPrintMultipleWarnings full = flip evalState M.empty . prettyPrintMultipleErrorsWith Warning "Warning:" "Multiple warnings:" full
738−prettyPrintMultipleErrorsWith :: String -> String -> Bool -> MultipleErrors -> State UnknownMap String
744+prettyPrintMultipleErrorsWith :: Level -> String -> String -> Bool -> MultipleErrors -> State UnknownMap String
739−prettyPrintMultipleErrorsWith intro _ full (MultipleErrors [e]) = do
745+prettyPrintMultipleErrorsWith level intro _ full (MultipleErrors [e]) = do
740− result <- prettyPrintSingleError full e
746+ result <- prettyPrintSingleError full level e
741 return $ renderBox $
747 return $ renderBox $
742 Box.vcat Box.left [ Box.text intro
748 Box.vcat Box.left [ Box.text intro
745−prettyPrintMultipleErrorsWith _ intro full (MultipleErrors es) = do
751+prettyPrintMultipleErrorsWith level _ intro full (MultipleErrors es) = do
746− result <- forM es $ (liftM $ Box.moveRight 2) . prettyPrintSingleError full
752+ result <- forM es $ (liftM $ Box.moveRight 2) . prettyPrintSingleError full level
747 return $ renderBox $
753 return $ renderBox $
748 Box.vcat Box.left [ Box.text intro
754 Box.vcat Box.left [ Box.text intro
749 , Box.vsep 1 Box.left result
755 , Box.vsep 1 Box.left result