on master help sign in
Rename post-type-checks to Nitpick

Also detach this code for now so I can make a coherent nitpicking process that includes top-level type declarations as well.

commit54df18ab9881265b2a3dfe81c61db64475320db2 authorEvan Czaplicki <info@elm-lang.org> dateWed 6 May 2015, 16:43 (11 years ago) parent1b95db0
6 files changed+29−36
src/Compile.hs−9 src/CheckMatch.hs → src/Nitpick/PatternMatches.hs+20−18 src/Reporting/Error.hs−2 src/Reporting/Error/CheckMatch.hs → src/Reporting/Error/Nitpick.hs+4−3 src/Reporting/Warning.hs+1−3 src/Reporting/Warning/CheckMatch.hs → src/Reporting/Warning/Nitpick.hs+4−1
src/Compile.hs−9
@@ -9,10 +9,8 @@ import qualified Parse.Parse as Parse
99import qualified Reporting.Error as Error
1010import qualified Reporting.Result as Result
1111import qualified Reporting.Warning as Warning
12−import qualified Reporting.Annotation as A
1312import qualified Type.Inference as TI
1413import qualified Canonicalize
15−import qualified CheckMatch
1614
1715
1816compile
@@ -46,13 +44,6 @@ compile user projectName interfaces source =
4644 -- Add the real list of tyes
4745 let body = (Module.body canonicalModule) { Module.types = types }
4846
49− case CheckMatch.checkBody interfaces body of
50− Left (A.A r matchError) ->
51− Result.throw r (Error.CheckMatch matchError)
52−
53− Right matchWarnings ->
54− Result.addWarnings (map (A.map Warning.MatchWarning) matchWarnings) (return ())
55−
5647 return $ canonicalModule { Module.body = body }
5748
5849
src/CheckMatch.hs → src/Nitpick/PatternMatches.hsrenamed+20−18
@@ -1,30 +1,27 @@
11{-# LANGUAGE NamedFieldPuns, TupleSections #-}
2−module CheckMatch
2+module Nitpick.PatternMatches
33 ( checkBody
44 , Pat (..)
55 , CanonicalPat
66 ) where
77
88import Control.Applicative ((<$>), (<*>))
9−import Control.Monad.Except (throwError)
10−import Control.Monad (liftM)
11−import Control.Monad (forM)
12−
9+import Control.Monad.Except (forM, liftM, throwError)
1310import Data.Maybe (mapMaybe, catMaybes)
1411import qualified Data.Set as Set
1512import qualified Data.Map as Map
1613
17−import Elm.Utils ((|>))
1814import qualified AST.Expression.General as General
1915import qualified AST.Expression.Canonical as Canonical
2016import qualified AST.Module as Module
2117import qualified AST.Pattern as Pattern
22−import AST.Pattern (CanonicalPattern)
18+import qualified AST.Variable as Var
19+import Elm.Utils ((|>))
2320import qualified Reporting.Annotation as Annotation
21+import qualified Reporting.Error.Nitpick as Error
2422import qualified Reporting.Region as Region
25−import qualified AST.Variable as Var
26−import qualified Reporting.Error.CheckMatch as Error
27−import Reporting.Warning.CheckMatch
23+import qualified Reporting.Warning.Nitpick as Warning
24+
2825
2926type M =
3027 Either (Annotation.Located Error.Error)
@@ -80,7 +77,7 @@ checkBody interfaces =
8077 General.Let defs e ->
8178 concat <$> sequence [ps, rhssResults, checkExpr e]
8279 where
83− ps = mapMaybeM (\(Canonical.Definition p _ _) -> checkMatch r [p]) defs
80+ ps = filterMapM (\(Canonical.Definition p _ _) -> checkMatch r [p]) defs
8481
8582 rhssResults = concatMapM (\(Canonical.Definition _ e _) -> checkExpr e) defs
8683
@@ -252,17 +249,22 @@ checkBody interfaces =
252249
253250
254251-- Util
252+
255253concatMapM :: Monad m => (a -> m [b]) -> [a] -> m [b]
256−concatMapM f =
257− liftM concat . mapM f
254+concatMapM f list =
255+ liftM concat (mapM f list)
258256
259257
260−mapMaybeM :: Monad m => (a -> m (Maybe b)) -> [a] -> m [b]
261−mapMaybeM f =
262− liftM catMaybes . mapM f
258+filterMapM :: Monad m => (a -> m (Maybe b)) -> [a] -> m [b]
259+filterMapM f list =
260+ liftM catMaybes (mapM f list)
263261
264262
265263maybeCons :: Maybe a -> [a] -> [a]
266−maybeCons =
267− maybe id (:)
264+maybeCons maybe list =
265+ case maybe of
266+ Just x ->
267+ x : list
268268
269+ Nothing ->
270+ list
src/Reporting/Error.hs−2
@@ -5,7 +5,6 @@ import qualified Reporting.Annotation as A
55import qualified Reporting.Error.Canonicalize as Canonicalize
66import qualified Reporting.Error.Syntax as Syntax
77import qualified Reporting.Error.Type as Type
8−import qualified Reporting.Error.CheckMatch as CheckMatch
98import qualified Reporting.Report as Report
109
1110
@@ -15,7 +14,6 @@ data Error
1514 = Syntax Syntax.Error
1615 | Canonicalize Canonicalize.Error
1716 | Type Type.Error
18− | CheckMatch CheckMatch.Error
1917
2018
2119-- TO STRING
src/Reporting/Error/CheckMatch.hs → src/Reporting/Error/Nitpick.hsrenamed+4−3
@@ -1,10 +1,11 @@
1−module Reporting.Error.CheckMatch where
1+module Reporting.Error.Nitpick where
22
33import qualified Data.Aeson as Json
44
55import qualified AST.Variable as Var
66import qualified Reporting.Region as R
77
8+
89data Error = ConstructorTypeNotFound Var.Canonical
910
1011-- TO STRING
@@ -12,7 +13,7 @@ data Error = ConstructorTypeNotFound Var.Canonical
1213toString :: R.Region -> Error -> String
1314toString region err =
1415 case err of
15− _ -> error "CheckMatch.toString" region
16+ _ -> error "Nitpick.toString" region
1617
1718
1819-- TO JSON
@@ -20,5 +21,5 @@ toString region err =
2021toJson :: Error -> Json.Value
2122toJson err =
2223 case err of
23− _ -> error "CheckMatch.toJson"
24+ _ -> error "Nitpick.toJson"
2425
src/Reporting/Warning.hs+1−3
@@ -4,13 +4,11 @@ import qualified AST.Module as Module
44
55import qualified Reporting.Annotation as A
66
7−import qualified Reporting.Warning.CheckMatch as CheckMatch
8−
97
108data Warning
119 = UnusedImport Module.Name
1210 | MissingTypeAnnotation String
13− | MatchWarning CheckMatch.Warning
11+
1412
1513-- TO STRING
1614
src/Reporting/Warning/CheckMatch.hs → src/Reporting/Warning/Nitpick.hsrenamed+4−1
@@ -1,10 +1,11 @@
1−module Reporting.Warning.CheckMatch where
1+module Reporting.Warning.Nitpick where
22
33import qualified AST.Pattern as Pattern
44import qualified AST.Literal as Literal
55import qualified Data.Set as Set
66import qualified AST.Variable as Var
77
8+
89data Pat var
910 = Data var [Pat var]
1011 | Record [String]
@@ -17,9 +18,11 @@ data Pat var
1718 | AnythingBut (Set.Set Literal.Literal)
1819 deriving (Show, Eq)
1920
21+
2022type CanonicalPat =
2123 Pat Var.Canonical
2224
25+
2326data Warning
2427 = Redundant Pattern.CanonicalPattern
2528 -- The argument is the list of patterns that would have to