on master help sign in
Fully represent possible patterns (add locals and tuples)
d492e71Evan Czaplicki
elm-compiler.cabal+1
@@ -79,6 +79,7 @@ Library
79 Generate.JavaScript.Helpers,
79 Generate.JavaScript.Helpers,
80 Generate.JavaScript.Port,
80 Generate.JavaScript.Port,
81 Generate.JavaScript.Variable,
81 Generate.JavaScript.Variable,
82+ Nitpick.PatternMatches,
82 Nitpick.TopLevelTypes,
83 Nitpick.TopLevelTypes,
83 Optimize,
84 Optimize,
84 Optimize.Cases,
85 Optimize.Cases,
src/Compile.hs+1−1
@@ -48,7 +48,7 @@ compile user projectName isRoot interfaces source =
48 Result.mapError Error.Type $
48 Result.mapError Error.Type $
49 Nitpick.topLevelTypes types (Module.body validModule)
49 Nitpick.topLevelTypes types (Module.body validModule)
50
50
51− Nitpick.patternMatches interfaces (Module.body canonicalModule)
51+ Nitpick.patternMatches interfaces canonicalModule
52
52
53 -- Add the real list of types
53 -- Add the real list of types
54 let body = (Module.body canonicalModule) { Module.types = types }
54 let body = (Module.body canonicalModule) { Module.types = types }
src/Nitpick/PatternMatches.hs+16−5
@@ -9,6 +9,7 @@ import qualified Data.Set as Set
9
9
10import qualified AST.Expression.General as E
10import qualified AST.Expression.General as E
11import qualified AST.Expression.Canonical as Canonical
11import qualified AST.Expression.Canonical as Canonical
12+import qualified AST.Helpers as Help
12import qualified AST.Literal as L
13import qualified AST.Literal as L
13import qualified AST.Module as Module
14import qualified AST.Module as Module
14import qualified AST.Pattern as P
15import qualified AST.Pattern as P
@@ -22,10 +23,16 @@ import qualified Reporting.Warning as Warning
22
23
23patternMatches
24patternMatches
24 :: Module.Interfaces
25 :: Module.Interfaces
25− -> Module.Body Canonical.Expr
26+ -> Module.CanonicalModule
26 -> Result.Result Warning.Warning e ()
27 -> Result.Result Warning.Warning e ()
27−patternMatches interfaces body =
28+patternMatches interfaces modul =
29+ let
30+ name = Module.names modul
31+ body = Module.body modul
32+ in
33+ checkExpression
34+ (toTagDict interfaces name (Module.datatypes body))
28− checkExpression (toTagDict interfaces) (Module.program body)
35+ (Module.program body)
29
36
30
37
31-- PATTERN MATCH DATA STRUCTURE
38-- PATTERN MATCH DATA STRUCTURE
@@ -73,8 +80,8 @@ type TagDict =
73type Tag = String
80type Tag = String
74
81
75
82
76−toTagDict :: Module.Interfaces -> TagDict
83+toTagDict :: Module.Interfaces -> Module.Name -> Module.ADTs -> TagDict
77−toTagDict interfaces =
84+toTagDict interfaces localName localAdts =
78 let
85 let
79 listTags =
86 listTags =
80 [ ("::", 2), ("[]", 0) ]
87 [ ("::", 2), ("[]", 0) ]
@@ -90,6 +97,7 @@ toTagDict interfaces =
90 interfaces
97 interfaces
91 |> Map.map (toTagMapping . Module.iAdts)
98 |> Map.map (toTagMapping . Module.iAdts)
92 |> Map.mapKeysMonotonic Var.Module
99 |> Map.mapKeysMonotonic Var.Module
100+ |> Map.insert (Var.Module localName) (toTagMapping localAdts)
93 in
101 in
94 Map.union builtinDict interfaceDict
102 Map.union builtinDict interfaceDict
95
103
@@ -115,6 +123,9 @@ lookupOtherCtors (Var.Canonical home name) tagDict =
115 otherTags
123 otherTags
116
124
117 Nothing ->
125 Nothing ->
126+ if Help.isTuple name then
127+ [(name, read (drop 6 name))]
128+ else
118 error
129 error
119 "Since the Nitpick phase happens after canonicalization and type \
130 "Since the Nitpick phase happens after canonicalization and type \
120 \inference, it is impossible that a pattern in a case cannot be \
131 \inference, it is impossible that a pattern in a case cannot be \