on master help sign in
Disambiguate when different types (and type aliases) in errors
eb39dd7Evan Czaplicki
compiler/src/Reporting/Doc.hs+1−1
@@ -5,7 +5,7 @@ module Reporting.Doc
5 , (P.<+>), (<>)
5 , (P.<+>), (<>)
6 , P.align, P.cat, P.empty, P.fill, P.fillSep, P.hang
6 , P.align, P.cat, P.empty, P.fill, P.fillSep, P.hang
7 , P.hcat, P.hsep, P.indent, P.sep, P.vcat
7 , P.hcat, P.hsep, P.indent, P.sep, P.vcat
8− , P.red, P.cyan, P.magenta, P.green, P.blue, P.black
8+ , P.red, P.cyan, P.magenta, P.green, P.blue, P.black, P.yellow
9 , P.dullred, P.dullcyan, P.dullyellow
9 , P.dullred, P.dullcyan, P.dullyellow
10
10
11 , fromString, fromText, fromName, fromInt
11 , fromString, fromText, fromName, fromInt
compiler/src/Reporting/Render/Type.hs+2−3
@@ -18,7 +18,6 @@ import qualified Data.Maybe as Maybe
18
18
19import qualified AST.Source as Src
19import qualified AST.Source as Src
20import qualified AST.Canonical as Can
20import qualified AST.Canonical as Can
21−import qualified AST.Module.Name as ModuleName
22import qualified Elm.Name as N
21import qualified Elm.Name as N
23import qualified Reporting.Annotation as A
22import qualified Reporting.Annotation as A
24import qualified Reporting.Doc as D
23import qualified Reporting.Doc as D
@@ -213,7 +212,7 @@ canToDoc localizer context tipe =
213 Can.TVar name ->
212 Can.TVar name ->
214 D.fromName name
213 D.fromName name
215
214
216− Can.TType (ModuleName.Canonical _ home) name args ->
215+ Can.TType home name args ->
217 apply context
216 apply context
218 (L.toDoc localizer home name)
217 (L.toDoc localizer home name)
219 (map (canToDoc localizer App) args)
218 (map (canToDoc localizer App) args)
@@ -232,7 +231,7 @@ canToDoc localizer context tipe =
232 (canToDoc localizer None b)
231 (canToDoc localizer None b)
233 (map (canToDoc localizer None) (Maybe.maybeToList maybeC))
232 (map (canToDoc localizer None) (Maybe.maybeToList maybeC))
234
233
235− Can.TAlias (ModuleName.Canonical _ home) name args _ ->
234+ Can.TAlias home name args _ ->
236 apply context
235 apply context
237 (L.toDoc localizer home name)
236 (L.toDoc localizer home name)
238 (map (canToDoc localizer App . snd) args)
237 (map (canToDoc localizer App . snd) args)
compiler/src/Reporting/Render/Type/Localizer.hs+13−6
@@ -3,6 +3,7 @@
3module Reporting.Render.Type.Localizer
3module Reporting.Render.Type.Localizer
4 ( Localizer
4 ( Localizer
5 , toDoc
5 , toDoc
6+ , toString
6 , empty
7 , empty
7 , fromNames
8 , fromNames
8 , fromModule
9 , fromModule
@@ -16,6 +17,7 @@ import qualified Data.Map as Map
16import qualified Data.Set as Set
17import qualified Data.Set as Set
17
18
18import qualified AST.Source as Src
19import qualified AST.Source as Src
20+import qualified AST.Module.Name as ModuleName
19import qualified AST.Valid as Valid
21import qualified AST.Valid as Valid
20import qualified Elm.Compiler.Imports as Imports
22import qualified Elm.Compiler.Imports as Imports
21import qualified Elm.Name as N
23import qualified Elm.Name as N
@@ -54,22 +56,27 @@ empty =
54-- LOCALIZE
56-- LOCALIZE
55
57
56
58
57−toDoc :: Localizer -> N.Name -> N.Name -> D.Doc
59+toDoc :: Localizer -> ModuleName.Canonical -> N.Name -> D.Doc
60+toDoc localizer home name =
61+ D.fromString (toString localizer home name)
62+
63+
64+toString :: Localizer -> ModuleName.Canonical -> N.Name -> String
58−toDoc (Localizer localizer) home name =
65+toString (Localizer localizer) (ModuleName.Canonical _ home) name =
59 case Map.lookup home localizer of
66 case Map.lookup home localizer of
60 Nothing ->
67 Nothing ->
61− D.fromName home <> "." <> D.fromName name
68+ N.toString home <> "." <> N.toString name
62
69
63 Just (Import alias exposing) ->
70 Just (Import alias exposing) ->
64 case exposing of
71 case exposing of
65 All ->
72 All ->
66− D.fromName name
73+ N.toString name
67
74
68 Only set ->
75 Only set ->
69 if Set.member name set then
76 if Set.member name set then
70− D.fromName name
77+ N.toString name
71 else
78 else
72− D.fromName (maybe home id alias) <> "." <> D.fromName name
79+ N.toString (maybe home id alias) <> "." <> N.toString name
73
80
74
81
75
82
compiler/src/Type/Error.hs+53−24
@@ -19,6 +19,7 @@ module Type.Error
19
19
20import qualified Data.Map as Map
20import qualified Data.Map as Map
21import qualified Data.Maybe as Maybe
21import qualified Data.Maybe as Maybe
22+import Data.Monoid ((<>))
22
23
23import qualified AST.Module.Name as ModuleName
24import qualified AST.Module.Name as ModuleName
24import qualified Data.Bag as Bag
25import qualified Data.Bag as Bag
@@ -75,11 +76,6 @@ iteratedDealias tipe =
75-- TO DOC
76-- TO DOC
76
77
77
78
78−nameToDoc :: L.Localizer -> ModuleName.Canonical -> N.Name -> D.Doc
79−nameToDoc localizer (ModuleName.Canonical _ home) name =
80− L.toDoc localizer home name
81−
82−
83toDoc :: L.Localizer -> RT.Context -> Type -> D.Doc
79toDoc :: L.Localizer -> RT.Context -> Type -> D.Doc
84toDoc localizer ctx tipe =
80toDoc localizer ctx tipe =
85 case tipe of
81 case tipe of
@@ -109,7 +105,7 @@ toDoc localizer ctx tipe =
109
105
110 Type home name args ->
106 Type home name args ->
111 RT.apply ctx
107 RT.apply ctx
112− (nameToDoc localizer home name)
108+ (L.toDoc localizer home name)
113 (map (toDoc localizer RT.App) args)
109 (map (toDoc localizer RT.App) args)
114
110
115 Record fields ext ->
111 Record fields ext ->
@@ -131,7 +127,7 @@ toDoc localizer ctx tipe =
131aliasToDoc :: L.Localizer -> RT.Context -> ModuleName.Canonical -> N.Name -> [(N.Name, Type)] -> D.Doc
127aliasToDoc :: L.Localizer -> RT.Context -> ModuleName.Canonical -> N.Name -> [(N.Name, Type)] -> D.Doc
132aliasToDoc localizer ctx home name args =
128aliasToDoc localizer ctx home name args =
133 RT.apply ctx
129 RT.apply ctx
134− (nameToDoc localizer home name)
130+ (L.toDoc localizer home name)
135 (map (toDoc localizer RT.App . snd) args)
131 (map (toDoc localizer RT.App . snd) args)
136
132
137
133
@@ -273,48 +269,70 @@ toDiff localizer ctx tipe1 tipe2 =
273 diffRecord localizer fields1 ext1 fields2 ext2
269 diffRecord localizer fields1 ext1 fields2 ext2
274
270
275 (Type home1 name1 args1, Type home2 name2 args2) | home1 == home2 && name1 == name2 ->
271 (Type home1 name1 args1, Type home2 name2 args2) | home1 == home2 && name1 == name2 ->
276− RT.apply ctx (nameToDoc localizer home1 name1)
272+ RT.apply ctx (L.toDoc localizer home1 name1)
277 <$> sequenceA (zipWith (toDiff localizer RT.App) args1 args2)
273 <$> sequenceA (zipWith (toDiff localizer RT.App) args1 args2)
278
274
279 (Alias home1 name1 args1 _, Alias home2 name2 args2 _) | home1 == home2 && name1 == name2 ->
275 (Alias home1 name1 args1 _, Alias home2 name2 args2 _) | home1 == home2 && name1 == name2 ->
280− RT.apply ctx (nameToDoc localizer home1 name1)
276+ RT.apply ctx (L.toDoc localizer home1 name1)
281 <$> sequenceA (zipWith (toDiff localizer RT.App) (map snd args1) (map snd args2))
277 <$> sequenceA (zipWith (toDiff localizer RT.App) (map snd args1) (map snd args2))
282
278
283 -- start trying to find specific problems
279 -- start trying to find specific problems
284
280
281+ (Type home1 name1 args1, Type home2 name2 args2) | L.toString localizer home1 name1 == L.toString localizer home2 name2 ->
282+ different
283+ (nameClashToDoc ctx localizer home1 name1 args1)
284+ (nameClashToDoc ctx localizer home2 name2 args2)
285+ Bag.empty
286+
285 (Type home name [t1], t2) | isMaybe home name && isSimilar (toDiff localizer ctx t1 t2) ->
287 (Type home name [t1], t2) | isMaybe home name && isSimilar (toDiff localizer ctx t1 t2) ->
286 different
288 different
287− (RT.apply ctx (D.dullyellow (nameToDoc localizer home name)) [toDoc localizer RT.App t1])
289+ (RT.apply ctx (D.dullyellow (L.toDoc localizer home name)) [toDoc localizer RT.App t1])
288 (toDoc localizer ctx t2)
290 (toDoc localizer ctx t2)
289 (Bag.one AnythingFromMaybe)
291 (Bag.one AnythingFromMaybe)
290
292
291 (t1, Type home name [t2]) | isList home name && isSimilar (toDiff localizer ctx t1 t2) ->
293 (t1, Type home name [t2]) | isList home name && isSimilar (toDiff localizer ctx t1 t2) ->
292 different
294 different
293 (toDoc localizer ctx t1)
295 (toDoc localizer ctx t1)
294− (RT.apply ctx (D.dullyellow (nameToDoc localizer home name)) [toDoc localizer RT.App t2])
296+ (RT.apply ctx (D.dullyellow (L.toDoc localizer home name)) [toDoc localizer RT.App t2])
295 (Bag.one AnythingToList)
297 (Bag.one AnythingToList)
296
298
297− (Alias home name args t1, t2) ->
299+ (Alias home1 name1 args1 t1, t2) ->
298 case diffAliasedRecord localizer t1 t2 of
300 case diffAliasedRecord localizer t1 t2 of
299 Just (Diff _ doc2 status) ->
301 Just (Diff _ doc2 status) ->
300− Diff (D.dullyellow (aliasToDoc localizer ctx home name args)) doc2 status
302+ Diff (D.dullyellow (aliasToDoc localizer ctx home1 name1 args1)) doc2 status
301
303
302 Nothing ->
304 Nothing ->
305+ case t2 of
306+ Type home2 name2 args2 | L.toString localizer home1 name1 == L.toString localizer home2 name2 ->
303− different
307+ different
308+ (nameClashToDoc ctx localizer home1 name1 (map snd args1))
309+ (nameClashToDoc ctx localizer home2 name2 args2)
310+ Bag.empty
311+
312+ _ ->
313+ different
304− (D.dullyellow (toDoc localizer ctx tipe1))
314+ (D.dullyellow (toDoc localizer ctx tipe1))
305− (D.dullyellow (toDoc localizer ctx tipe2))
315+ (D.dullyellow (toDoc localizer ctx tipe2))
306− Bag.empty
316+ Bag.empty
307−
317+
308− (t1, Alias home name args t2) ->
318+ (t1, Alias home2 name2 args2 t2) ->
309 case diffAliasedRecord localizer t1 t2 of
319 case diffAliasedRecord localizer t1 t2 of
310 Just (Diff doc1 _ status) ->
320 Just (Diff doc1 _ status) ->
311− Diff doc1 (D.dullyellow (aliasToDoc localizer ctx home name args)) status
321+ Diff doc1 (D.dullyellow (aliasToDoc localizer ctx home2 name2 args2)) status
312
322
313 Nothing ->
323 Nothing ->
324+ case t1 of
325+ Type home1 name1 args1 | L.toString localizer home1 name1 == L.toString localizer home2 name2 ->
314− different
326+ different
327+ (nameClashToDoc ctx localizer home1 name1 args1)
328+ (nameClashToDoc ctx localizer home2 name2 (map snd args2))
329+ Bag.empty
330+
331+ _ ->
332+ different
315− (D.dullyellow (toDoc localizer ctx tipe1))
333+ (D.dullyellow (toDoc localizer ctx tipe1))
316− (D.dullyellow (toDoc localizer ctx tipe2))
334+ (D.dullyellow (toDoc localizer ctx tipe2))
317− Bag.empty
335+ Bag.empty
318
336
319 pair ->
337 pair ->
320 let
338 let
@@ -430,6 +448,17 @@ isSuper super tipe =
430
448
431
449
432
450
451+-- NAME CLASH
452+
453+
454+nameClashToDoc :: RT.Context -> L.Localizer -> ModuleName.Canonical -> N.Name -> [Type] -> D.Doc
455+nameClashToDoc ctx localizer (ModuleName.Canonical _ home) name args =
456+ RT.apply ctx
457+ (D.yellow (D.fromName home) <> D.dullyellow ("." <> D.fromName name))
458+ (map (toDoc localizer RT.App) args)
459+
460+
461+
433-- DIFF ALIASED RECORD
462-- DIFF ALIASED RECORD
434
463
435
464