1{-# OPTIONS_GHC -Wall #-}
2module Reporting.Error.Pattern where
4import qualified Data.Set as Set
5import Text.PrettyPrint.ANSI.Leijen (text)
7import qualified Nitpick.Pattern as Pattern
8import qualified Reporting.Error.Helpers as Help
9import qualified Reporting.Render.Type as RenderType
10import qualified Reporting.Report as Report
15 = Incomplete Origin (Set.Set Pattern.Pattern)
29toReport :: RenderType.Localizer -> Error -> Report.Report
30toReport _localizer err =
32 Incomplete Arg unhandled ->
36 "This pattern does not cover all possible inputs."
37 (text (unhandledError unhandled toCaseMessage))
39 Incomplete LetBound unhandled ->
43 "The pattern used here does not cover all possible values."
44 (text (unhandledError unhandled toCaseMessage))
46 Incomplete Case unhandled ->
50 "This `case` does not have branches for all possibilities."
51 (text (unhandledError unhandled (missingBranchesMessage (length unhandled))))
57 "The following pattern is redundant. Remove it."
58 (text "Any value with this shape will be handled by a previous pattern.")
61unhandledError :: Set.Set Pattern.Pattern -> String -> String
62unhandledError unhandledPatterns relevantMessage =
64 (visiblePatterns, rest) =
65 splitAt 4 (Set.toList unhandledPatterns)
68 map (Pattern.toString False) visiblePatterns
69 ++ if null rest then [] else ["..."]
71 "You need to account for the following values:\n"
72 ++ concatMap ("\n " ++) patternList ++ "\n"
74 ++ relevantMessage ++ "\n"
76 ++ "If you are seeing this error for the first time, check out these hints:\n"
77 ++ Help.hintLink "missing-patterns" ++ "\n"
78 ++ "The recommendations about wildcard patterns and `Debug.crash` are important!"
81toCaseMessage :: String
83 "Switch to a `case` expression to handle all possible patterns."
86missingBranchesMessage :: Int -> String
87missingBranchesMessage numUnhandled =
88 if numUnhandled == 1 then
89 "Add a branch to cover this pattern!"
92 "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