on master help sign in
Underline type when type annotation does not match body
commit6ea2189873bfbb2760be0cdb251bc2753282c5b7 authorEvan Czaplicki <info@elm-lang.org> dateFri 29 May 2015, 21:39 (11 years ago) parent516b777
4 files changed+26−16
src/AST/Expression/Canonical.hs+2−1 src/Canonicalize.hs+13−5 src/Canonicalize/Declaration.hs+9−8 src/Type/Constrain/Expression.hs+2−2
src/AST/Expression/Canonical.hs+2−1
@@ -7,6 +7,7 @@ import qualified AST.Expression.General as General
77import qualified AST.Pattern as Pattern
88import qualified AST.Type as Type
99import qualified AST.Variable as Var
10+import qualified Reporting.Annotation as A
1011import qualified Reporting.PrettyPrint as P
1112import qualified Reporting.Region as R
1213
@@ -23,7 +24,7 @@ type Expr' =
2324
2425
2526data Def
26− = Definition Pattern.CanonicalPattern Expr (Maybe Type.Canonical)
27+ = Definition Pattern.CanonicalPattern Expr (Maybe (A.Located Type.Canonical))
2728 deriving (Show)
2829
2930
src/Canonicalize.hs+13−5
@@ -265,12 +265,12 @@ declaration
265265declaration env (A.A (region,_) decl) =
266266 A.A region <$>
267267 case decl of
268− D.Definition (Valid.Definition p e t) ->
268+ D.Definition (Valid.Definition pat expr typ) ->
269269 D.Definition <$> (
270270 Canonical.Definition
271− <$> pattern env p
272− <*> expression env e
273− <*> T.traverse (Canonicalize.tipe env) t
271+ <$> pattern env pat
272+ <*> expression env expr
273+ <*> T.traverse (regionType env) typ
274274 )
275275
276276 D.Datatype name tvars ctors ->
@@ -306,6 +306,14 @@ declaration env (A.A (region,_) decl) =
306306 Result.ok (D.Fixity assoc prec op)
307307
308308
309+regionType
310+ :: Env.Environment
311+ -> Type.Raw
312+ -> Result.ResultErr (A.Located Type.Canonical)
313+regionType env typ@(A.A region _) =
314+ A.A region <$> Canonicalize.tipe env typ
315+
316+
309317expression
310318 :: Env.Environment
311319 -> Valid.Expr
@@ -369,7 +377,7 @@ expression env (A.A region validExpr) =
369377 Canonical.Definition
370378 <$> pattern env' p
371379 <*> expression env' body
372− <*> T.traverse (Canonicalize.tipe env') mtipe
380+ <*> T.traverse (regionType env') mtipe
373381
374382 Var (Var.Raw x) ->
375383 Var <$> Canonicalize.variable region env x
src/Canonicalize/Declaration.hs+9−8
@@ -9,6 +9,7 @@ import qualified AST.Pattern as P
99import qualified AST.Type as T
1010import qualified AST.Variable as Var
1111import qualified Reporting.Annotation as A
12+import qualified Reporting.Region as R
1213
1314
1415toExpr :: Module.Name -> [D.CanonicalDecl] -> [Canonical.Def]
@@ -35,10 +36,10 @@ toDefs moduleName (A.A region decl) =
3536 tbody = T.App (T.Type (typeVar name)) (map T.Var tvars)
3637 body = loc . E.Data ctor $ map (loc . E.localVar) vars
3738 in
38− [ definition ctor (buildFunction body vars) (foldr T.Lambda tbody tipes) ]
39+ [ definition ctor (buildFunction body vars) region (foldr T.Lambda tbody tipes) ]
3940
4041 D.TypeAlias name tvars tipe@(T.Record fields ext) ->
41− [ definition name (buildFunction record vars) (foldr T.Lambda result args) ]
42+ [ definition name (buildFunction record vars) region (foldr T.Lambda result args) ]
4243 where
4344 result =
4445 T.Aliased (typeVar name) (zip tvars (map T.Var tvars)) (T.Holey tipe)
@@ -70,13 +71,13 @@ toDefs moduleName (A.A region decl) =
7071 in
7172 case impl of
7273 E.In name tipe ->
73− [ definition name body (T.getPortType tipe) ]
74+ [ definition name body region (T.getPortType tipe) ]
7475
7576 E.Out name _expr tipe ->
76− [ definition name body (T.getPortType tipe) ]
77+ [ definition name body region (T.getPortType tipe) ]
7778
7879 E.Task name _expr tipe ->
79− [ definition name body (T.getPortType tipe) ]
80+ [ definition name body region (T.getPortType tipe) ]
8081
8182 -- no constraints are needed for fixity declarations
8283 D.Fixity _ _ _ ->
@@ -96,6 +97,6 @@ buildFunction body@(A.A ann _) vars =
9697 (map (A.A ann . P.Var) vars)
9798
9899
99−definition :: String -> Canonical.Expr -> T.Canonical -> Canonical.Def
100−definition name expr@(A.A ann _) tipe =
101− Canonical.Definition (A.A ann (P.Var name)) expr (Just tipe)
100+definition :: String -> Canonical.Expr -> R.Region -> T.Canonical -> Canonical.Def
101+definition name expr@(A.A ann _) region tipe =
102+ Canonical.Definition (A.A ann (P.Var name)) expr (Just (A.A region tipe))
src/Type/Constrain/Expression.hs+2−2
@@ -416,11 +416,11 @@ data Info = Info
416416
417417
418418constrainDef :: Env.Environment -> Info -> Canonical.Def -> IO Info
419−constrainDef env info (Canonical.Definition (A.A region pattern) expr maybeTipe) =
419+constrainDef env info (Canonical.Definition (A.A _ pattern) expr maybeTipe) =
420420 let qs = [] -- should come from the def, but I'm not sure what would live there...
421421 in
422422 case (pattern, maybeTipe) of
423− (P.Var name, Just tipe) ->
423+ (P.Var name, Just (A.A region tipe)) ->
424424 constrainAnnotatedDef env info qs region name expr tipe
425425
426426 (P.Var name, Nothing) ->