on master help sign in
Fully represent possible patterns (add locals and tuples)
commitd492e71f1ef0772bde7c02862272b79af2eeabf0 authorEvan Czaplicki <info@elm-lang.org> dateSat 15 Aug 2015, 01:37 (11 years ago) parent9d9e439
3 files changed+18−6
elm-compiler.cabal+1 src/Compile.hs+1−1 src/Nitpick/PatternMatches.hs+16−5
elm-compiler.cabal+1
@@ -79,6 +79,7 @@ Library
7979 Generate.JavaScript.Helpers,
8080 Generate.JavaScript.Port,
8181 Generate.JavaScript.Variable,
82+ Nitpick.PatternMatches,
8283 Nitpick.TopLevelTypes,
8384 Optimize,
8485 Optimize.Cases,
src/Compile.hs+1−1
@@ -48,7 +48,7 @@ compile user projectName isRoot interfaces source =
4848 Result.mapError Error.Type $
4949 Nitpick.topLevelTypes types (Module.body validModule)
5050
51− Nitpick.patternMatches interfaces (Module.body canonicalModule)
51+ Nitpick.patternMatches interfaces canonicalModule
5252
5353 -- Add the real list of types
5454 let body = (Module.body canonicalModule) { Module.types = types }
src/Nitpick/PatternMatches.hs+16−5
@@ -9,6 +9,7 @@ import qualified Data.Set as Set
99
1010import qualified AST.Expression.General as E
1111import qualified AST.Expression.Canonical as Canonical
12+import qualified AST.Helpers as Help
1213import qualified AST.Literal as L
1314import qualified AST.Module as Module
1415import qualified AST.Pattern as P
@@ -22,10 +23,16 @@ import qualified Reporting.Warning as Warning
2223
2324patternMatches
2425 :: Module.Interfaces
25− -> Module.Body Canonical.Expr
26+ -> Module.CanonicalModule
2627 -> Result.Result Warning.Warning e ()
27−patternMatches interfaces body =
28− checkExpression (toTagDict interfaces) (Module.program 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))
35+ (Module.program body)
2936
3037
3138-- PATTERN MATCH DATA STRUCTURE
@@ -73,8 +80,8 @@ type TagDict =
7380type Tag = String
7481
7582
76−toTagDict :: Module.Interfaces -> TagDict
77−toTagDict interfaces =
83+toTagDict :: Module.Interfaces -> Module.Name -> Module.ADTs -> TagDict
84+toTagDict interfaces localName localAdts =
7885 let
7986 listTags =
8087 [ ("::", 2), ("[]", 0) ]
@@ -90,6 +97,7 @@ toTagDict interfaces =
9097 interfaces
9198 |> Map.map (toTagMapping . Module.iAdts)
9299 |> Map.mapKeysMonotonic Var.Module
100+ |> Map.insert (Var.Module localName) (toTagMapping localAdts)
93101 in
94102 Map.union builtinDict interfaceDict
95103
@@ -115,6 +123,9 @@ lookupOtherCtors (Var.Canonical home name) tagDict =
115123 otherTags
116124
117125 Nothing ->
126+ if Help.isTuple name then
127+ [(name, read (drop 6 name))]
128+ else
118129 error
119130 "Since the Nitpick phase happens after canonicalization and type \
120131 \inference, it is impossible that a pattern in a case cannot be \