@@ -16,6 +16,7 @@ import qualified AST.Pattern as Pattern
16import qualified AST.Variable as Var
16import qualified AST.Variable as Var
17import Elm.Utils ((|>))
17import Elm.Utils ((|>))
18import Nitpick.Pattern (Pattern(..), fromCanonicalPattern)
18import Nitpick.Pattern (Pattern(..), fromCanonicalPattern)
19+import qualified Optimize.Patterns.DecisionTree as Opt
19import qualified Reporting.Annotation as A
20import qualified Reporting.Annotation as A
20import qualified Reporting.Error.Pattern as Error
21import qualified Reporting.Error.Pattern as Error
21import qualified Reporting.Region as Region
22import qualified Reporting.Region as Region
@@ -25,31 +26,40 @@ import qualified Reporting.Result as Result
25patternMatches
26patternMatches
26 :: Module.Interfaces
27 :: Module.Interfaces
27 -> Module.CanonicalModule
28 -> Module.CanonicalModule
28− -> Result.Result w Error.Error ()
29+ -> Result.Result w Error.Error Opt.VariantDict
29patternMatches interfaces modul =
30patternMatches interfaces modul =
31 name = Module.name modul
32 name = Module.name modul
32 body = Module.body modul
33 body = Module.body modul
35+ toTagDict interfaces name (Module.datatypes body)
34− checkExpression
37+ const (Map.map (Map.map length) tagDict)
35− (toTagDict interfaces name (Module.datatypes body))
36− (Module.program body)
38+ <$> checkExpression tagDict (Module.program body)
39-- TAG DICT
41-- TAG DICT
41type TagDict =
43type TagDict =
42− Map.Map Var.Home (Map.Map Tag [(Tag, Int)])
44+ Map.Map Var.Home (Map.Map Tag [TagInfo])
45type Tag = String
47type Tag = String
50+data TagInfo = TagInfo
48toTagDict :: Module.Interfaces -> ModuleName.Canonical -> Module.ADTs -> TagDict
56toTagDict :: Module.Interfaces -> ModuleName.Canonical -> Module.ADTs -> TagDict
49toTagDict interfaces localName localAdts =
57toTagDict interfaces localName localAdts =
51 listTags =
59 listTags =
52− [ ("::", 2), ("[]", 0) ]
60+ [ TagInfo "::" 2
54 builtinDict =
64 builtinDict =
55 Map.singleton Var.BuiltIn $
65 Map.singleton Var.BuiltIn $
@@ -67,12 +77,12 @@ toTagDict interfaces localName localAdts =
67 Map.union builtinDict interfaceDict
77 Map.union builtinDict interfaceDict
70−toTagMapping :: Module.ADTs -> Map.Map Tag ([(Tag,Int)])
80+toTagMapping :: Module.ADTs -> Map.Map Tag [TagInfo]
71toTagMapping adts =
81toTagMapping adts =
73 toTagAndArity (_tvars, tagInfoList) =
83 toTagAndArity (_tvars, tagInfoList) =
75− info = map (\(tag, args) -> (tag, length args)) tagInfoList
85+ info = map (\(tag, args) -> TagInfo tag (length args)) tagInfoList
77 map (second (const info)) tagInfoList
87 map (second (const info)) tagInfoList
@@ -81,7 +91,7 @@ toTagMapping adts =
81 |> Map.fromList
91 |> Map.fromList
84−lookupOtherTags :: Var.Canonical -> TagDict -> [(Tag, Int)]
94+lookupOtherTags :: Var.Canonical -> TagDict -> [TagInfo]
85lookupOtherTags (Var.Canonical home name) tagDict =
95lookupOtherTags (Var.Canonical home name) tagDict =
86 case Map.lookup name =<< Map.lookup home tagDict of
96 case Map.lookup name =<< Map.lookup home tagDict of
87 Just otherTags ->
97 Just otherTags ->
@@ -89,7 +99,7 @@ lookupOtherTags (Var.Canonical home name) tagDict =
90 Nothing ->
100 Nothing ->
91 if Help.isTuple name then
101 if Help.isTuple name then
92− [(name, read (drop 6 name))]
102+ [ TagInfo name (read (drop 6 name)) ]
95 "Since the Nitpick phase happens after canonicalization and type \
105 "Since the Nitpick phase happens after canonicalization and type \
@@ -339,8 +349,8 @@ complementData tagDict tag patterns =
339 tagComplements ++ argComplements
349 tagComplements ++ argComplements
342−tagToPattern :: Var.Canonical -> (Tag, Int) -> Maybe Pattern
352+tagToPattern :: Var.Canonical -> TagInfo -> Maybe Pattern
343−tagToPattern (Var.Canonical home rootTag) (tag, arity) =
353+tagToPattern (Var.Canonical home rootTag) (TagInfo tag arity) =
344 if rootTag == tag then
354 if rootTag == tag then