@@ -10,11 +10,11 @@ import qualified Data.Set as Set
1010import qualified AST.Expression.General as E
1111import qualified AST.Expression.Canonical as Canonical
1212import qualified AST.Helpers as Help
13−import qualified AST.Literal as L
1413import qualified AST.Module as Module
15−import qualified AST.Pattern as P
14+import qualified AST.Pattern as Pattern
1615import qualified AST.Variable as Var
1716import Elm.Utils ((|>))
17+import Nitpick.Pattern (Pattern(..), fromCanonicalPattern)
1818import qualified Reporting.Annotation as A
1919import qualified Reporting.Region as Region
2020import qualified Reporting.Result as Result
@@ -35,42 +35,6 @@ patternMatches interfaces modul =
3535 (Module.program body)
3636
3737
38−-- PATTERN MATCH DATA STRUCTURE
39−
40−data Pattern
41− = Data Var.Canonical [Pattern]
42− | Record [String]
43− | Alias String Pattern
44− | Var String
45− | Anything
46− | Literal L.Literal
47− | AnythingBut (Set.Set L.Literal)
48− deriving (Show, Eq)
49−
50−
51−fromCanonicalPattern :: P.CanonicalPattern -> Pattern
52−fromCanonicalPattern (A.A _ pattern) =
53− case pattern of
54− P.Data ctor patterns ->
55− Data ctor (map fromCanonicalPattern patterns)
56−
57− P.Record fields ->
58− Record fields
59−
60− P.Alias name pattern ->
61− Alias name (fromCanonicalPattern pattern)
62−
63− P.Var name ->
64− Var name
65−
66− P.Anything ->
67− Anything
68−
69− P.Literal literal ->
70− Literal literal
71−
72−
73−
7438-- TAG DICT
7539
7640type TagDict =
@@ -116,8 +80,8 @@ toTagMapping adts =
11680 |> Map.fromList
11781
11882
119−lookupOtherCtors :: Var.Canonical -> TagDict -> [(Tag, Int)]
120−lookupOtherCtors (Var.Canonical home name) tagDict =
83+lookupOtherTags :: Var.Canonical -> TagDict -> [(Tag, Int)]
84+lookupOtherTags (Var.Canonical home name) tagDict =
12185 case Map.lookup name =<< Map.lookup home tagDict of
12286 Just otherTags ->
12387 otherTags
@@ -144,7 +108,7 @@ checkExpression tagDict (A.A region expression) =
144108 checkExpression tagDict
145109
146110 go2 a b =
147− F.traverse_ go [a,b]
111+ go a <* go b
148112
149113 goPattern =
150114 checkPatterns tagDict region
@@ -157,8 +121,7 @@ checkExpression tagDict (A.A region expression) =
157121 Result.ok ()
158122
159123 E.Range low high ->
160− go low
161− <* go high
124+ go2 low high
162125
163126 E.ExplicitList listExprs ->
164127 F.traverse_ go listExprs
@@ -232,7 +195,7 @@ checkExpression tagDict (A.A region expression) =
232195checkPatterns
233196 :: TagDict
234197 -> Region.Region
235− -> [P.CanonicalPattern]
198+ -> [Pattern.CanonicalPattern]
236199 -> Result.Result Warning.Warning e ()
237200checkPatterns tagDict region patterns =
238201 checkPatternsHelp tagDict region [Anything] patterns
@@ -242,7 +205,7 @@ checkPatternsHelp
242205 :: TagDict
243206 -> Region.Region
244207 -> [Pattern]
245− -> [P.CanonicalPattern]
208+ -> [Pattern.CanonicalPattern]
246209 -> Result.Result Warning.Warning e ()
247210checkPatternsHelp tagDict region unhandled patterns =
248211 case (unhandled, patterns) of
@@ -250,7 +213,7 @@ checkPatternsHelp tagDict region unhandled patterns =
250213 return ()
251214
252215 (_:_, []) ->
253− Result.warn region Warning.InexhaustivePatternMatch
216+ Result.warn region (Warning.InexhaustivePatternMatch unhandled)
254217
255218 (_, pattern@(A.A localRegion _) : remainingPatterns) ->
256219 do newUnhandled <- filterPatterns tagDict localRegion pattern unhandled
@@ -260,7 +223,7 @@ checkPatternsHelp tagDict region unhandled patterns =
260223filterPatterns
261224 :: TagDict
262225 -> Region.Region
263− -> P.CanonicalPattern
226+ -> Pattern.CanonicalPattern
264227 -> [Pattern]
265228 -> Result.Result Warning.Warning e [Pattern]
266229filterPatterns tagDict region pattern unhandled =
@@ -370,7 +333,7 @@ complementData :: TagDict -> Var.Canonical -> [Pattern] -> [Pattern]
370333complementData tagDict tag patterns =
371334 let
372335 otherTags =
373− lookupOtherCtors tag tagDict
336+ lookupOtherTags tag tagDict
374337
375338 tagComplements =
376339 Maybe.mapMaybe (tagToPattern tag) otherTags