git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Merge pull request #1252 from mjgpy3/1250_say_warning_when_warning
9b20545Phil Freeman
src/Language/PureScript/Errors.hs+33−27
@@ -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
274
274
275+-- | How critical the issue is
276+data Level = Error | Warning deriving Show
277+
275-- |
278-- |
276-- Extract nested error messages from wrapper errors
279-- Extract nested error messages from wrapper errors
277--
280--
@@ -344,8 +347,8 @@ onTypesInErrorMessageM f = g
344-- |
347-- |
345-- Pretty print a single error, simplifying if necessary
348-- Pretty print a single error, simplifying if necessary
346--
349--
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)
349 where
352 where
350 -- |
353 -- |
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
374 ]
377 ]
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
378 ]
381 ]
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
562 ]
565 ]
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
568 , go err
571 , go err
569 ]
572 ]
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
573 , go err
576 , go err
574 ]
577 ]
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 ++ ":"
577 , go err
580 , go err
578 ]
581 ]
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
584 , go err
587 , go err
585 ]
588 ]
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) ++ ":"
588 , go err
591 , go err
589 ]
592 ]
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
593 , go err
596 , go err
594 ]
597 ]
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
598 , go err
601 , go err
599 ]
602 ]
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
605 , go err
608 , go err
606 ]
609 ]
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
614 , go err
617 , go err
615 ]
618 ]
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 ++ ":"
618 , go err
621 , go err
619 ]
622 ]
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 ++ ":"
622 , go err
625 , go err
623 ]
626 ]
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) ++ ":"
626 , go err
629 , go err
627 ]
630 ]
628 go (ErrorInDataBindingGroup err) =
631 go (ErrorInDataBindingGroup err) =
629− paras [ line $ "Error in data binding group:"
632+ paras [ lineWithLevel $ "in data binding group:"
630 , go err
633 , go err
631 ]
634 ]
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 ++ ":"
634 , go err
637 , go err
635 ]
638 ]
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 ++ ":"
638 , go err
641 , go err
639 ]
642 ]
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 ++ ":"
642 , go err
645 , go err
643 ]
646 ]
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
647 ]
650 ]
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
652
655
656+ lineWithLevel :: String -> Box.Box
657+ lineWithLevel text = line $ show level ++ " " ++ text
658+
653 suggestions :: ErrorMessage -> [Box.Box]
659 suggestions :: ErrorMessage -> [Box.Box]
654 suggestions = suggestions' . unwrapErrorMessage
660 suggestions = suggestions' . unwrapErrorMessage
655 where
661 where
@@ -727,23 +733,23 @@ prettyPrintSingleError full e = prettyPrintErrorMessage <$> onTypesInErrorMessag
727-- Pretty print multiple errors
733-- Pretty print multiple errors
728--
734--
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
731
737
732-- |
738-- |
733-- Pretty print multiple warnings
739-- Pretty print multiple warnings
734--
740--
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
737
743
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
743 , result
749 , result
744 ]
750 ]
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