1{-# OPTIONS_GHC -Wall #-}
2module Reporting.Error.Pattern where
4import Text.PrettyPrint.ANSI.Leijen (text)
6import qualified Nitpick.Pattern as Pattern
7import qualified Reporting.Error.Helpers as Help
8import qualified Reporting.Render.Type as RenderType
9import qualified Reporting.Report as Report
14 = Incomplete Origin [Pattern.Pattern]
28toReport :: RenderType.Localizer -> Error -> Report.Report
29toReport _localizer err =
31 Incomplete Arg unhandled ->
35 "This pattern does not cover all possible inputs."
36 (text (unhandledError unhandled toCaseMessage))
38 Incomplete LetBound unhandled ->
42 "The pattern used here does not cover all possible values."
43 (text (unhandledError unhandled toCaseMessage))
45 Incomplete Case unhandled ->
49 "This `case` does not have branches for all possibilities."
50 (text (unhandledError unhandled (missingBranchesMessage (length unhandled))))
56 "The following pattern is redundant. Remove it."
57 (text "Any value with this shape will be handled by a previous pattern.")
60unhandledError :: [Pattern.Pattern] -> String -> String
61unhandledError unhandledPatterns relevantMessage =
63 (visiblePatterns, rest) =
64 splitAt 4 unhandledPatterns
67 map (Pattern.toString False) visiblePatterns
68 ++ if null rest then [] else ["..."]
70 "You need to account for the following values:\n"
71 ++ concatMap ("\n " ++) patternList ++ "\n"
73 ++ relevantMessage ++ "\n"
75 ++ "If you are seeing this error for the first time, check out these hints:\n"
76 ++ Help.hintLink "missing-patterns" ++ "\n"
77 ++ "The recommendations about wildcard patterns and `Debug.crash` are important!"
80toCaseMessage :: String
82 "Switch to a `case` expression to handle all possible patterns."
85missingBranchesMessage :: Int -> String
86missingBranchesMessage numUnhandled =
87 if numUnhandled == 1 then
88 "Add a branch to cover this pattern!"
91 "Add branches to cover each of these patterns!"
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list