1{-# OPTIONS_GHC -Wall #-}
2module Reporting.Error.Pattern where
4import qualified Data.Char as Char
5import Text.PrettyPrint ((<+>))
6import qualified Text.PrettyPrint as P
8import qualified AST.Helpers as Help
9import qualified AST.Type as Type
10import qualified AST.Variable as Var
11import qualified Nitpick.Pattern as Pattern
12import qualified Reporting.PrettyPrint as P
13import qualified Reporting.Region as Region
14import qualified Reporting.Report as Report
18 = Incomplete [Pattern.Pattern]
24toReport :: P.Dealiaser -> Error -> Report.Report
25toReport dealiaser err =
27 Incomplete unhandled ->
30 "The following `case` does not handle all possible inputs."
31 ( "The following patterns are not being handled:\n"
32 ++ viewPatternList unhandled
34 ++ incompleteExplanation
40 "The following pattern is redundant."
41 "Any value with this shape will be handled by a previous pattern."
44viewPatternList :: [Pattern.Pattern] -> String
45viewPatternList unhandledPatterns =
47 (showPatterns, rest) =
48 splitAt 4 unhandledPatterns
50 concatMap ((++) "\n ") $
51 map (Pattern.toString False) showPatterns
52 ++ if null rest then [] else ["..."]
55incompleteExplanation :: String
56incompleteExplanation =
58 [ "Did you add a new tag to a union type? Add how it should be handled here and"
59 , "you will be all set!"
61 , "If you want to go quick and implement this later, you can end the pattern with:"
64 , " Debug.crash \"TODO\""
66 , "When I see cases that end with this pattern, I augment the runtime error with"
67 , "the module name, the relevant line numbers, and the value led down that branch."
69 , "That said, you almost never want this in production code. If you think there"
70 , "are certain cases that are impossible in practice, consider refining how you"
71 , "model the data. If it can never happen in practice, you can probably define a"
72 , "union type such that the \"impossible\" cannot even be constructed in the"
73 , "first place. That is how you make something \"impossible\" truly impossible."
75 , "I won't say \"I told you so\" in the runtime error, but I'll be thinking it ;)"
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