1{-# OPTIONS_GHC -Wall #-}
2{-# LANGUAGE OverloadedStrings #-}
3module Reporting.Error.Pattern where
6import qualified Data.Text as Text
8import qualified Nitpick.Pattern as Pattern
9import qualified Reporting.Render.Type as RenderType
10import qualified Reporting.Region as Region
11import qualified Reporting.Report as Report
12import qualified Reporting.Helpers as Help
13import Reporting.Helpers ((<>), text)
18 = Incomplete Origin [Pattern.Pattern]
19 | Redundant Region.Region Int
32toReport :: RenderType.Localizer -> Error -> Report.Report
33toReport _localizer err =
35 Incomplete Arg unhandled ->
39 "This pattern does not cover all possible inputs."
40 (text (unhandledError unhandled toCaseMessage))
42 Incomplete LetBound unhandled ->
46 "The pattern used here does not cover all possible values."
47 (text (unhandledError unhandled toCaseMessage))
49 Incomplete Case unhandled ->
53 "This `case` does not have branches for all possibilities."
54 (text (unhandledError unhandled (missingBranchesMessage (length unhandled))))
56 Redundant region index ->
60 ("The " <> Help.ordinalize index <> " pattern is redundant. Remove it.")
61 (text "Any value with this shape will be handled by a previous pattern.")
64unhandledError :: [Pattern.Pattern] -> Text -> Text
65unhandledError unhandledPatterns relevantMessage =
67 (visiblePatterns, rest) =
68 splitAt 4 unhandledPatterns
71 map Pattern.toText visiblePatterns
72 ++ if null rest then [] else ["..."]
75 if length unhandledPatterns == 1 then "pattern" else "patterns"
77 "You need to account for the following " <> noun <> ":\n"
78 <> Text.concat (map ("\n " <>) patternList) <> "\n"
80 <> relevantMessage <> "\n"
82 <> "If you are seeing this error for the first time, check out these hints:\n"
83 <> Help.hintLink "missing-patterns" <> "\n"
84 <> "The recommendations about wildcard patterns and `Debug.crash` are important!"
89 "Switch to a `case` expression to handle all possible patterns."
92missingBranchesMessage :: Int -> Text
93missingBranchesMessage numUnhandled =
94 if numUnhandled == 1 then
95 "Add a branch to cover this pattern!"
98 "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