@@ -19,6 +19,7 @@ module Type.Error
1919
2020import qualified Data.Map as Map
2121import qualified Data.Maybe as Maybe
22+import Data.Monoid ((<>))
2223
2324import qualified AST.Module.Name as ModuleName
2425import qualified Data.Bag as Bag
@@ -75,11 +76,6 @@ iteratedDealias tipe =
7576-- TO DOC
7677
7778
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−
8379toDoc :: L.Localizer -> RT.Context -> Type -> D.Doc
8480toDoc localizer ctx tipe =
8581 case tipe of
@@ -109,7 +105,7 @@ toDoc localizer ctx tipe =
109105
110106 Type home name args ->
111107 RT.apply ctx
112− (nameToDoc localizer home name)
108+ (L.toDoc localizer home name)
113109 (map (toDoc localizer RT.App) args)
114110
115111 Record fields ext ->
@@ -131,7 +127,7 @@ toDoc localizer ctx tipe =
131127aliasToDoc :: L.Localizer -> RT.Context -> ModuleName.Canonical -> N.Name -> [(N.Name, Type)] -> D.Doc
132128aliasToDoc localizer ctx home name args =
133129 RT.apply ctx
134− (nameToDoc localizer home name)
130+ (L.toDoc localizer home name)
135131 (map (toDoc localizer RT.App . snd) args)
136132
137133
@@ -273,48 +269,70 @@ toDiff localizer ctx tipe1 tipe2 =
273269 diffRecord localizer fields1 ext1 fields2 ext2
274270
275271 (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)
277273 <$> sequenceA (zipWith (toDiff localizer RT.App) args1 args2)
278274
279275 (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)
281277 <$> sequenceA (zipWith (toDiff localizer RT.App) (map snd args1) (map snd args2))
282278
283279 -- start trying to find specific problems
284280
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+
285287 (Type home name [t1], t2) | isMaybe home name && isSimilar (toDiff localizer ctx t1 t2) ->
286288 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])
288290 (toDoc localizer ctx t2)
289291 (Bag.one AnythingFromMaybe)
290292
291293 (t1, Type home name [t2]) | isList home name && isSimilar (toDiff localizer ctx t1 t2) ->
292294 different
293295 (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])
295297 (Bag.one AnythingToList)
296298
297− (Alias home name args t1, t2) ->
299+ (Alias home1 name1 args1 t1, t2) ->
298300 case diffAliasedRecord localizer t1 t2 of
299301 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
301303
302304 Nothing ->
303− different
304− (D.dullyellow (toDoc localizer ctx tipe1))
305− (D.dullyellow (toDoc localizer ctx tipe2))
306− Bag.empty
307−
308− (t1, Alias home name args t2) ->
305+ case t2 of
306+ Type home2 name2 args2 | L.toString localizer home1 name1 == L.toString localizer home2 name2 ->
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
314+ (D.dullyellow (toDoc localizer ctx tipe1))
315+ (D.dullyellow (toDoc localizer ctx tipe2))
316+ Bag.empty
317+
318+ (t1, Alias home2 name2 args2 t2) ->
309319 case diffAliasedRecord localizer t1 t2 of
310320 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
312322
313323 Nothing ->
314− different
315− (D.dullyellow (toDoc localizer ctx tipe1))
316− (D.dullyellow (toDoc localizer ctx tipe2))
317− Bag.empty
324+ case t1 of
325+ Type home1 name1 args1 | L.toString localizer home1 name1 == L.toString localizer home2 name2 ->
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
333+ (D.dullyellow (toDoc localizer ctx tipe1))
334+ (D.dullyellow (toDoc localizer ctx tipe2))
335+ Bag.empty
318336
319337 pair ->
320338 let
@@ -430,6 +448,17 @@ isSuper super tipe =
430448
431449
432450
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+
433462-- DIFF ALIASED RECORD
434463
435464