on master help sign in
Start flowing Localizer through other modules
commitcb14fe8e71c0804b01a894e5e5694f2a8ea3f503 authorEvan Czaplicki <evancz@users.noreply.github.com> dateWed 18 Apr 2018, 14:31 (9 years ago) parentf320cea
5 files changed+108−112
compiler/src/Compile.hs+7−4 compiler/src/Elm/Compiler.hs+2−2 compiler/src/Reporting/Error/Type.hs+23−22 compiler/src/Type/Error.hs+74−83 compiler/src/Type/Solve.hs+2−1
compiler/src/Compile.hs+7−4
@@ -10,6 +10,8 @@ module Compile
1010import qualified Data.ByteString as BS
1111import qualified Data.Map as Map
1212
13+import qualified AST.Source as Src
14+import qualified AST.Valid as Valid
1315import qualified AST.Canonical as Can
1416import qualified AST.Optimized as Opt
1517import qualified AST.Module.Name as ModuleName
@@ -22,6 +24,7 @@ import qualified Nitpick.PatternMatches as PatternMatches
2224import qualified Optimize.Module as Optimize
2325import qualified Parse.Parse as Parse
2426import qualified Reporting.Error as Error
27+import qualified Reporting.Render.Type.Localizer as L
2528import qualified Reporting.Result as Result
2629import qualified Reporting.Warning as Warning
2730import qualified Type.Constrain.Module as Type
@@ -60,7 +63,7 @@ compile flag pkg importDict interfaces source =
6063 Canonicalize.canonicalize pkg importDict interfaces valid
6164
6265 annotations <-
63− runTypeInference canonical
66+ runTypeInference (Valid._imports valid) canonical
6467
6568 () <-
6669 exhaustivenessCheck canonical
@@ -83,11 +86,11 @@ compile flag pkg importDict interfaces source =
8386-- TYPE INFERENCE
8487
8588
86−runTypeInference :: Can.Module -> Result i (Map.Map N.Name Can.Annotation)
87−runTypeInference canonical =
89+runTypeInference :: [Src.Import] -> Can.Module -> Result i (Map.Map N.Name Can.Annotation)
90+runTypeInference imports canonical =
8891 case unsafePerformIO (Type.run =<< Type.constrain canonical) of
8992 Left errors ->
90− Result.throw (Error.Type errors)
93+ Result.throw (Error.Type (L.fromImports imports) errors)
9194
9295 Right annotations ->
9396 Result.ok annotations
compiler/src/Elm/Compiler.hs+2−2
@@ -66,7 +66,7 @@ errorsToDoc :: FilePath -> Text.Text -> [Error.Error] -> D.Doc
6666errorsToDoc filePath source errors =
6767 let
6868 reports =
69− concatMap (Error.toReports (Code.toSource source) Map.empty) errors
69+ concatMap (Error.toReports (Code.toSource source)) errors
7070 in
7171 D.vcat $ map (Report.toDoc filePath) reports
7272
@@ -79,7 +79,7 @@ errorsToJson :: M.Raw -> FilePath -> Text.Text -> [Error.Error] -> Encode.Value
7979errorsToJson moduleName filePath source errors =
8080 let
8181 reports =
82− concatMap (Error.toReports (Code.toSource source) Map.empty) errors
82+ concatMap (Error.toReports (Code.toSource source)) errors
8383 in
8484 Encode.object
8585 [ ("path", Encode.text (Text.pack filePath))
compiler/src/Reporting/Error/Type.hs+23−22
@@ -28,6 +28,7 @@ import qualified Reporting.Doc as D
2828import qualified Reporting.Region as R
2929import qualified Reporting.Render.Code as Code
3030import qualified Reporting.Render.Type as RT
31+import qualified Reporting.Render.Type.Localizer as L
3132import qualified Reporting.Report as Report
3233import qualified Type.Error as T
3334
@@ -161,7 +162,7 @@ ptypeReplace expectation tipe =
161162-- TO REPORT
162163
163164
164−toReport :: Code.Source -> T.Localizer -> Error -> Report.Report
165+toReport :: Code.Source -> L.Localizer -> Error -> Report.Report
165166toReport source localizer err =
166167 case err of
167168 BadExpr region category actualType expected ->
@@ -178,7 +179,7 @@ toReport source localizer err =
178179-- TO PATTERN REPORT
179180
180181
181−toPatternReport :: Code.Source -> T.Localizer -> R.Region -> PCategory -> T.Type -> PExpected T.Type -> Report.Report
182+toPatternReport :: Code.Source -> L.Localizer -> R.Region -> PCategory -> T.Type -> PExpected T.Type -> Report.Report
182183toPatternReport source localizer patternRegion category tipe expected =
183184 Report.Report "TYPE MISMATCH" patternRegion [] $
184185 case expected of
@@ -306,7 +307,7 @@ toPatternReport source localizer patternRegion category tipe expected =
306307-- PATTERN HELPERS
307308
308309
309−patternTypeComparison :: T.Localizer -> T.Type -> T.Type -> ( String, String, [D.Doc] ) -> D.Doc
310+patternTypeComparison :: L.Localizer -> T.Type -> T.Type -> ( String, String, [D.Doc] ) -> D.Doc
310311patternTypeComparison localizer actual expected ( iAmSeeing, insteadOf, contextHints ) =
311312 let
312313 (actualDoc, expectedDoc, problems) =
@@ -340,7 +341,7 @@ toPatternDescription category iAmTryingToMatch =
340341-- EXPR HELPERS
341342
342343
343−typeComparison :: T.Localizer -> T.Type -> T.Type -> ( String, String, [D.Doc] ) -> D.Doc
344+typeComparison :: L.Localizer -> T.Type -> T.Type -> ( String, String, [D.Doc] ) -> D.Doc
344345typeComparison localizer actual expected ( iAmSeeing, insteadOf, contextHints ) =
345346 let
346347 (actualDoc, expectedDoc, problems) =
@@ -356,7 +357,7 @@ typeComparison localizer actual expected ( iAmSeeing, insteadOf, contextHints )
356357 ++ contextHints
357358
358359
359−loneType :: T.Localizer -> T.Type -> T.Type -> ( D.Doc, [D.Doc] ) -> D.Doc
360+loneType :: L.Localizer -> T.Type -> T.Type -> ( D.Doc, [D.Doc] ) -> D.Doc
360361loneType localizer actual expected ( iAmSeeing, furtherDetails ) =
361362 let
362363 (actualDoc, _, problems) =
@@ -634,7 +635,7 @@ badFlexFlexSuper s1 s2 =
634635-- TO EXPR REPORT
635636
636637
637−toExprReport :: Code.Source -> T.Localizer -> R.Region -> Category -> T.Type -> Expected T.Type -> Report.Report
638+toExprReport :: Code.Source -> L.Localizer -> R.Region -> Category -> T.Type -> Expected T.Type -> Report.Report
638639toExprReport source localizer exprRegion category tipe expected =
639640 Report.Report "TYPE MISMATCH" exprRegion [] $
640641 case expected of
@@ -1041,7 +1042,7 @@ countArgs tipe =
10411042-- OP LEFT
10421043
10431044
1044−opLeftToDocs :: T.Localizer -> Category -> N.Name -> T.Type -> T.Type -> (D.Doc, D.Doc)
1045+opLeftToDocs :: L.Localizer -> Category -> N.Name -> T.Type -> T.Type -> (D.Doc, D.Doc)
10451046opLeftToDocs localizer category op tipe expected =
10461047 case op of
10471048 "+"
@@ -1101,7 +1102,7 @@ data RightDocs
11011102 | EmphRight (D.Doc, D.Doc)
11021103
11031104
1104−opRightToDocs :: T.Localizer -> Category -> N.Name -> T.Type -> T.Type -> RightDocs
1105+opRightToDocs :: L.Localizer -> Category -> N.Name -> T.Type -> T.Type -> RightDocs
11051106opRightToDocs localizer category op tipe expected =
11061107 case op of
11071108 "+"
@@ -1192,7 +1193,7 @@ opRightToDocs localizer category op tipe expected =
11921193 badOpRightFallback localizer category op tipe expected
11931194
11941195
1195−badOpRightFallback :: T.Localizer -> Category -> N.Name -> T.Type -> T.Type -> RightDocs
1196+badOpRightFallback :: L.Localizer -> Category -> N.Name -> T.Type -> T.Type -> RightDocs
11961197badOpRightFallback localizer category op tipe expected =
11971198 EmphRight
11981199 (
@@ -1258,7 +1259,7 @@ isList tipe =
12581259-- BAD CONS
12591260
12601261
1261−badConsRight :: T.Localizer -> Category -> T.Type -> T.Type -> RightDocs
1262+badConsRight :: L.Localizer -> Category -> T.Type -> T.Type -> RightDocs
12621263badConsRight localizer category tipe expected =
12631264 case tipe of
12641265 T.Type home1 name1 [actualElement] | T.isList home1 name1 ->
@@ -1332,7 +1333,7 @@ toAppendType tipe =
13321333 _ -> AOther
13331334
13341335
1335−badAppendLeft :: T.Localizer -> Category -> T.Type -> T.Type -> (D.Doc, D.Doc)
1336+badAppendLeft :: L.Localizer -> Category -> T.Type -> T.Type -> (D.Doc, D.Doc)
13361337badAppendLeft localizer category tipe expected =
13371338 case toAppendType tipe of
13381339 ANumber thing stringFromThing ->
@@ -1367,7 +1368,7 @@ badAppendLeft localizer category tipe expected =
13671368 )
13681369
13691370
1370−badAppendRight :: T.Localizer -> Category -> T.Type -> T.Type -> RightDocs
1371+badAppendRight :: L.Localizer -> Category -> T.Type -> T.Type -> RightDocs
13711372badAppendRight localizer category tipe expected =
13721373 case (toAppendType expected, toAppendType tipe) of
13731374 (AString, ANumber thing stringFromThing) ->
@@ -1501,7 +1502,7 @@ badStringAdd =
15011502 )
15021503
15031504
1504−badListAdd :: T.Localizer -> Category -> String -> T.Type -> T.Type -> (D.Doc, D.Doc)
1505+badListAdd :: L.Localizer -> Category -> String -> T.Type -> T.Type -> (D.Doc, D.Doc)
15051506badListAdd localizer category direction tipe expected =
15061507 (
15071508 "I cannot do addition with lists:"
@@ -1522,7 +1523,7 @@ badListAdd localizer category direction tipe expected =
15221523 )
15231524
15241525
1525−badListMul :: T.Localizer -> Category -> String -> T.Type -> T.Type -> (D.Doc, D.Doc)
1526+badListMul :: L.Localizer -> Category -> String -> T.Type -> T.Type -> (D.Doc, D.Doc)
15261527badListMul localizer category direction tipe expected =
15271528 badMath localizer category "Multiplication" direction "*" tipe expected
15281529 [
@@ -1534,7 +1535,7 @@ badListMul localizer category direction tipe expected =
15341535 ]
15351536
15361537
1537−badMath :: T.Localizer -> Category -> String -> String -> String -> T.Type -> T.Type -> [D.Doc] -> (D.Doc, D.Doc)
1538+badMath :: L.Localizer -> Category -> String -> String -> String -> T.Type -> T.Type -> [D.Doc] -> (D.Doc, D.Doc)
15381539badMath localizer category operation direction op tipe expected otherHints =
15391540 (
15401541 D.reflow $
@@ -1554,7 +1555,7 @@ badMath localizer category operation direction op tipe expected otherHints =
15541555 )
15551556
15561557
1557−badFDiv :: T.Localizer -> D.Doc -> T.Type -> T.Type -> (D.Doc, D.Doc)
1558+badFDiv :: L.Localizer -> D.Doc -> T.Type -> T.Type -> (D.Doc, D.Doc)
15581559badFDiv localizer direction tipe expected =
15591560 (
15601561 D.reflow $
@@ -1588,7 +1589,7 @@ badFDiv localizer direction tipe expected =
15881589 )
15891590
15901591
1591−badIDiv :: T.Localizer -> D.Doc -> T.Type -> T.Type -> (D.Doc, D.Doc)
1592+badIDiv :: L.Localizer -> D.Doc -> T.Type -> T.Type -> (D.Doc, D.Doc)
15921593badIDiv localizer direction tipe expected =
15931594 (
15941595 D.reflow $
@@ -1628,7 +1629,7 @@ badIDiv localizer direction tipe expected =
16281629-- BAD BOOLS
16291630
16301631
1631−badBool :: T.Localizer -> D.Doc -> D.Doc -> T.Type -> T.Type -> (D.Doc, D.Doc)
1632+badBool :: L.Localizer -> D.Doc -> D.Doc -> T.Type -> T.Type -> (D.Doc, D.Doc)
16321633badBool localizer op direction tipe expected =
16331634 (
16341635 D.reflow $
@@ -1650,7 +1651,7 @@ badBool localizer op direction tipe expected =
16501651-- BAD COMPARISON
16511652
16521653
1653−badCompLeft :: T.Localizer -> Category -> String -> String -> T.Type -> T.Type -> (D.Doc, D.Doc)
1654+badCompLeft :: L.Localizer -> Category -> String -> String -> T.Type -> T.Type -> (D.Doc, D.Doc)
16541655badCompLeft localizer category op direction tipe expected =
16551656 (
16561657 D.reflow $
@@ -1677,7 +1678,7 @@ badCompLeft localizer category op direction tipe expected =
16771678 )
16781679
16791680
1680−badCompRight :: T.Localizer -> String -> T.Type -> T.Type -> RightDocs
1681+badCompRight :: L.Localizer -> String -> T.Type -> T.Type -> RightDocs
16811682badCompRight localizer op tipe expected =
16821683 EmphBoth
16831684 (
@@ -1701,7 +1702,7 @@ badCompRight localizer op tipe expected =
17011702-- BAD EQUALITY
17021703
17031704
1704−badEquality :: T.Localizer -> String -> T.Type -> T.Type -> RightDocs
1705+badEquality :: L.Localizer -> String -> T.Type -> T.Type -> RightDocs
17051706badEquality localizer op tipe expected =
17061707 EmphBoth
17071708 (
@@ -1731,7 +1732,7 @@ badEquality localizer op tipe expected =
17311732-- INFINITE TYPES
17321733
17331734
1734−toInfiniteReport :: Code.Source -> T.Localizer -> R.Region -> N.Name -> T.Type -> Report.Report
1735+toInfiniteReport :: Code.Source -> L.Localizer -> R.Region -> N.Name -> T.Type -> Report.Report
17351736toInfiniteReport source localizer region name overallType =
17361737 Report.Report "INFINITE TYPE" region [] $
17371738 Report.toCodeSnippet source region Nothing
compiler/src/Type/Error.hs+74−83
@@ -5,7 +5,6 @@ module Type.Error
55 , Super(..)
66 , Extension(..)
77 , iteratedDealias
8− , Localizer
98 , toDoc
109 , toDiffDocs
1110 , Problem(..)
@@ -20,13 +19,13 @@ module Type.Error
2019
2120import qualified Data.Map as Map
2221import qualified Data.Maybe as Maybe
23−import Data.Monoid ((<>))
2422
2523import qualified AST.Module.Name as ModuleName
2624import qualified Data.Bag as Bag
2725import qualified Elm.Name as N
2826import qualified Reporting.Doc as D
2927import qualified Reporting.Render.Type as RT
28+import qualified Reporting.Render.Type.Localizer as L
3029
3130
3231
@@ -75,27 +74,19 @@ iteratedDealias tipe =
7574-- TO DOC
7675
7776
78−type Localizer = Map.Map (ModuleName.Canonical, N.Name) String
77+nameToDoc :: L.Localizer -> ModuleName.Canonical -> N.Name -> D.Doc
78+nameToDoc localizer (ModuleName.Canonical _ home) name =
79+ L.toDoc localizer home name
7980
8081
81−nameToDoc :: Localizer -> ModuleName.Canonical -> N.Name -> D.Doc
82−nameToDoc dict home@(ModuleName.Canonical _ moduleName) name =
83− case Map.lookup (home, name) dict of
84− Nothing ->
85− D.fromName moduleName <> "." <> D.fromName name
86−
87− Just string ->
88− D.fromString string
89−
90−
91−toDoc :: Localizer -> RT.Context -> Type -> D.Doc
92−toDoc dict ctx tipe =
82+toDoc :: L.Localizer -> RT.Context -> Type -> D.Doc
83+toDoc localizer ctx tipe =
9384 case tipe of
9485 Lambda a b cs ->
9586 RT.lambda ctx
96− (toDoc dict RT.Func a)
97− (toDoc dict RT.Func b)
98− (map (toDoc dict RT.Func) cs)
87+ (toDoc localizer RT.Func a)
88+ (toDoc localizer RT.Func b)
89+ (map (toDoc localizer RT.Func) cs)
9990
10091 Infinite ->
10192 "∞"
@@ -117,13 +108,13 @@ toDoc dict ctx tipe =
117108
118109 Type home name args ->
119110 RT.apply ctx
120− (nameToDoc dict home name)
121− (map (toDoc dict RT.App) args)
111+ (nameToDoc localizer home name)
112+ (map (toDoc localizer RT.App) args)
122113
123114 Record fields ext ->
124115 let
125116 entryToDocs (fieldName, fieldType) =
126− ( D.fromName fieldName, toDoc dict RT.None fieldType )
117+ ( D.fromName fieldName, toDoc localizer RT.None fieldType )
127118
128119 fieldDocs =
129120 map entryToDocs (Map.toList fields)
@@ -139,23 +130,23 @@ toDoc dict ctx tipe =
139130
140131 Tuple a b maybeC ->
141132 RT.tuple
142− (toDoc dict RT.None a)
143− (toDoc dict RT.None b)
144− (map (toDoc dict RT.None) (Maybe.maybeToList maybeC))
133+ (toDoc localizer RT.None a)
134+ (toDoc localizer RT.None b)
135+ (map (toDoc localizer RT.None) (Maybe.maybeToList maybeC))
145136
146137 Alias home name args _ ->
147138 RT.apply ctx
148− (nameToDoc dict home name)
149− (map (toDoc dict RT.App . snd) args)
139+ (nameToDoc localizer home name)
140+ (map (toDoc localizer RT.App . snd) args)
150141
151142
152143
153144-- DIFF
154145
155146
156−toDiffDocs :: Localizer -> Type -> Type -> (D.Doc, D.Doc, [Problem])
157−toDiffDocs dict a b =
158− case diff dict RT.None a b of
147+toDiffDocs :: L.Localizer -> Type -> Type -> (D.Doc, D.Doc, [Problem])
148+toDiffDocs localizer a b =
149+ case diff localizer RT.None a b of
159150 Similar aDoc bDoc ->
160151 (aDoc, bDoc, [])
161152
@@ -217,8 +208,8 @@ data Problem
217208-- COMPUTE DIFF
218209
219210
220−diff :: Localizer -> RT.Context -> Type -> Type -> Diff D.Doc
221−diff dict ctx tipe1 tipe2 =
211+diff :: L.Localizer -> RT.Context -> Type -> Type -> Diff D.Doc
212+diff localizer ctx tipe1 tipe2 =
222213 case (tipe1, tipe2) of
223214 (FlexVar x, FlexVar y) | x == y -> pure (D.fromName x)
224215 (FlexSuper _ x, FlexSuper _ y) | x == y -> pure (D.fromName x)
@@ -231,45 +222,45 @@ diff dict ctx tipe1 tipe2 =
231222
232223 (Tuple a b maybeC, Tuple x y maybeZ) ->
233224 RT.tuple
234− <$> diff dict RT.None a x
235− <*> diff dict RT.None b y
225+ <$> diff localizer RT.None a x
226+ <*> diff localizer RT.None b y
236227 <*>
237228 case (maybeC, maybeZ) of
238229 (Nothing, Nothing) -> pure []
239− (Just c , Nothing) -> Different [D.dullyellow (toDoc dict RT.None c)] [] Bag.empty
240− (Nothing, Just z ) -> Different [] [D.dullyellow (toDoc dict RT.None z)] Bag.empty
241− (Just c , Just z ) -> (:[]) <$> diff dict RT.None c z
230+ (Just c , Nothing) -> Different [D.dullyellow (toDoc localizer RT.None c)] [] Bag.empty
231+ (Nothing, Just z ) -> Different [] [D.dullyellow (toDoc localizer RT.None z)] Bag.empty
232+ (Just c , Just z ) -> (:[]) <$> diff localizer RT.None c z
242233
243− (Record fields1 ext1, Record fields2 ext2) -> diffRecord dict fields1 ext1 fields2 ext2
234+ (Record fields1 ext1, Record fields2 ext2) -> diffRecord localizer fields1 ext1 fields2 ext2
244235
245236 (Type home1 name1 args1, Type home2 name2 args2) | home1 == home2 && name1 == name2 ->
246− RT.apply ctx (nameToDoc dict home1 name1) <$>
247− sequenceA (zipWith (diff dict RT.App) args1 args2)
237+ RT.apply ctx (nameToDoc localizer home1 name1) <$>
238+ sequenceA (zipWith (diff localizer RT.App) args1 args2)
248239
249240 (Alias home1 name1 args1 _, Alias home2 name2 args2 _) | home1 == home2 && name1 == name2 ->
250− RT.apply ctx (nameToDoc dict home1 name1) <$>
251− sequenceA (zipWith (diff dict RT.App) (map snd args1) (map snd args2))
241+ RT.apply ctx (nameToDoc localizer home1 name1) <$>
242+ sequenceA (zipWith (diff localizer RT.App) (map snd args1) (map snd args2))
252243
253− (Alias _ _ _ alias1, other) -> diff dict ctx alias1 other
254− (other, Alias _ _ _ alias2) -> diff dict ctx other alias2
244+ (Alias _ _ _ alias1, other) -> diff localizer ctx alias1 other
245+ (other, Alias _ _ _ alias2) -> diff localizer ctx other alias2
255246
256− (Lambda a b cs, Lambda x y zs) -> diffLambda dict ctx (a:b:cs) (x:y:zs)
247+ (Lambda a b cs, Lambda x y zs) -> diffLambda localizer ctx (a:b:cs) (x:y:zs)
257248
258− (FlexVar x, other) -> Similar (D.fromName x) (toDoc dict ctx other)
259− (other, FlexVar x) -> Similar (toDoc dict ctx other) (D.fromName x)
249+ (FlexVar x, other) -> Similar (D.fromName x) (toDoc localizer ctx other)
250+ (other, FlexVar x) -> Similar (toDoc localizer ctx other) (D.fromName x)
260251
261252 pair ->
262253 case pair of
263254 (Type home name [t1], t2) | isMaybe home name && isSimilar t1 t2 ->
264− Different (yellowApply dict ctx home name t1) (toDoc dict ctx t2) (Bag.one AnythingFromMaybe)
255+ Different (yellowApply localizer ctx home name t1) (toDoc localizer ctx t2) (Bag.one AnythingFromMaybe)
265256
266257 (t1, Type home name [t2]) | isList home name && isSimilar t1 t2 ->
267− Different (toDoc dict ctx t1) (yellowApply dict ctx home name t2) (Bag.one AnythingToList)
258+ Different (toDoc localizer ctx t1) (yellowApply localizer ctx home name t2) (Bag.one AnythingToList)
268259
269260 _ ->
270261 let
271− doc1 = D.dullyellow (toDoc dict ctx tipe1)
272− doc2 = D.dullyellow (toDoc dict ctx tipe2)
262+ doc1 = D.dullyellow (toDoc localizer ctx tipe1)
263+ doc2 = D.dullyellow (toDoc localizer ctx tipe2)
273264 in
274265 Different doc1 doc2 $
275266 case pair of
@@ -329,16 +320,16 @@ isList home name =
329320
330321isSimilar :: Type -> Type -> Bool
331322isSimilar tipe1 tipe2 =
332− case diff Map.empty RT.None tipe1 tipe2 of
323+ case diff L.empty RT.None tipe1 tipe2 of
333324 Similar _ _ -> True
334325 Different _ _ _ -> False
335326
336327
337−yellowApply :: Localizer -> RT.Context -> ModuleName.Canonical -> N.Name -> Type -> D.Doc
338−yellowApply dict ctx home name tipe =
328+yellowApply :: L.Localizer -> RT.Context -> ModuleName.Canonical -> N.Name -> Type -> D.Doc
329+yellowApply localizer ctx home name tipe =
339330 RT.apply ctx
340− (D.dullyellow (nameToDoc dict home name))
341− [toDoc dict RT.App tipe]
331+ (D.dullyellow (nameToDoc localizer home name))
332+ [toDoc localizer RT.App tipe]
342333
343334
344335
@@ -348,8 +339,8 @@ yellowApply dict ctx home name tipe =
348339--
349340-- INVARIANT: length types1 >= 2 && length types2 >= 2
350341--
351−diffLambda :: Localizer -> RT.Context -> [Type] -> [Type] -> Diff D.Doc
352−diffLambda dict ctx types1 types2 =
342+diffLambda :: L.Localizer -> RT.Context -> [Type] -> [Type] -> Diff D.Doc
343+diffLambda localizer ctx types1 types2 =
353344 let
354345 (result1:revArgs1) = reverse types1
355346 (result2:revArgs2) = reverse types2
@@ -357,7 +348,7 @@ diffLambda dict ctx types1 types2 =
357348 numArgs1 = length revArgs1
358349 numArgs2 = length revArgs2
359350
360− resultDiff = diff dict RT.Func result1 result2
351+ resultDiff = diff localizer RT.Func result1 result2
361352 in
362353 case resultDiff of
363354 Similar resultDoc1 resultDoc2 ->
@@ -367,18 +358,18 @@ diffLambda dict ctx types1 types2 =
367358 RT.lambda ctx x y zs
368359 )
369360 <$> resultDiff
370− <*> sequenceA (zipWith (diff dict RT.Func) revArgs1 revArgs2)
361+ <*> sequenceA (zipWith (diff localizer RT.Func) revArgs1 revArgs2)
371362
372363 else if numArgs1 < numArgs2 then
373− diffArgMismatch dict ctx revArgs1 resultDoc1 revArgs2 resultDoc2
364+ diffArgMismatch localizer ctx revArgs1 resultDoc1 revArgs2 resultDoc2
374365
375366 else
376− diffArgMismatch dict ctx revArgs2 resultDoc2 revArgs1 resultDoc1
367+ diffArgMismatch localizer ctx revArgs2 resultDoc2 revArgs1 resultDoc1
377368
378369 Different resultDoc1 resultDoc2 problems ->
379370 let
380− (x1:y1:zs1) = reverse (resultDoc1 : map (toDoc dict RT.Func) revArgs1)
381− (x2:y2:zs2) = reverse (resultDoc2 : map (toDoc dict RT.Func) revArgs2)
371+ (x1:y1:zs1) = reverse (resultDoc1 : map (toDoc localizer RT.Func) revArgs1)
372+ (x2:y2:zs2) = reverse (resultDoc2 : map (toDoc localizer RT.Func) revArgs2)
382373 in
383374 Different
384375 (RT.lambda ctx x1 y1 zs1)
@@ -389,9 +380,9 @@ diffLambda dict ctx types1 types2 =
389380--
390381-- INVARIANT: length shortRevArgs >= 2 && length longRevArgs >= 2
391382--
392−diffArgMismatch :: Localizer -> RT.Context -> [Type] -> D.Doc -> [Type] -> D.Doc -> Diff D.Doc
393−diffArgMismatch dict ctx shortRevArgs shortResult longRevArgs longResult =
394− case toGreedyMatch dict shortRevArgs longRevArgs of
383+diffArgMismatch :: L.Localizer -> RT.Context -> [Type] -> D.Doc -> [Type] -> D.Doc -> Diff D.Doc
384+diffArgMismatch localizer ctx shortRevArgs shortResult longRevArgs longResult =
385+ case toGreedyMatch localizer shortRevArgs longRevArgs of
395386 Just (GreedyMatch shortRevArgDocs longRevArgDocs) ->
396387 let
397388 (a:b:cs) = reverse (shortResult:shortRevArgDocs)
@@ -403,7 +394,7 @@ diffArgMismatch dict ctx shortRevArgs shortResult longRevArgs longResult =
403394 (Bag.one (MissingArgs (length longRevArgs - length shortRevArgs)))
404395
405396 Nothing ->
406− case toGreedyMatch dict (reverse shortRevArgs) (reverse longRevArgs) of
397+ case toGreedyMatch localizer (reverse shortRevArgs) (reverse longRevArgs) of
407398 Just (GreedyMatch shortArgDocs longArgDocs) ->
408399 let
409400 (a:b:cs) = shortArgDocs ++ [shortResult]
@@ -417,7 +408,7 @@ diffArgMismatch dict ctx shortRevArgs shortResult longRevArgs longResult =
417408 Nothing ->
418409 let
419410 toYellowDoc tipe =
420− D.dullyellow (toDoc dict RT.Func tipe)
411+ D.dullyellow (toDoc localizer RT.Func tipe)
421412
422413 (a:b:cs) = reverse (shortResult : map toYellowDoc shortRevArgs)
423414 (x:y:zs) = reverse (longResult : map toYellowDoc longRevArgs )
@@ -439,26 +430,26 @@ data GreedyMatch =
439430--
440431-- INVARIANT: length shorterArgs < length longerArgs
441432--
442−toGreedyMatch :: Localizer -> [Type] -> [Type] -> Maybe GreedyMatch
443−toGreedyMatch dict shorterArgs longerArgs =
444− toGreedyMatchHelp dict shorterArgs longerArgs (GreedyMatch [] [])
433+toGreedyMatch :: L.Localizer -> [Type] -> [Type] -> Maybe GreedyMatch
434+toGreedyMatch localizer shorterArgs longerArgs =
435+ toGreedyMatchHelp localizer shorterArgs longerArgs (GreedyMatch [] [])
445436
446437
447−toGreedyMatchHelp :: Localizer -> [Type] -> [Type] -> GreedyMatch -> Maybe GreedyMatch
448−toGreedyMatchHelp dict shorterArgs longerArgs match@(GreedyMatch shorterDocs longerDocs) =
438+toGreedyMatchHelp :: L.Localizer -> [Type] -> [Type] -> GreedyMatch -> Maybe GreedyMatch
439+toGreedyMatchHelp localizer shorterArgs longerArgs match@(GreedyMatch shorterDocs longerDocs) =
449440 let
450441 toYellowDoc tipe =
451− D.dullyellow (toDoc dict RT.Func tipe)
442+ D.dullyellow (toDoc localizer RT.Func tipe)
452443 in
453444 case (shorterArgs, longerArgs) of
454445 (x:xs, y:ys) ->
455− case diff dict RT.Func x y of
446+ case diff localizer RT.Func x y of
456447 Similar a b ->
457− toGreedyMatchHelp dict xs ys $
448+ toGreedyMatchHelp localizer xs ys $
458449 GreedyMatch (a:shorterDocs) (b:longerDocs)
459450
460451 Different _ _ _ ->
461− toGreedyMatchHelp dict shorterArgs ys $
452+ toGreedyMatchHelp localizer shorterArgs ys $
462453 GreedyMatch shorterDocs (toYellowDoc y : longerDocs)
463454
464455 ([], []) ->
@@ -475,14 +466,14 @@ toGreedyMatchHelp dict shorterArgs longerArgs match@(GreedyMatch shorterDocs lon
475466-- RECORD DIFFS
476467
477468
478−diffRecord :: Localizer -> Map.Map N.Name Type -> Extension -> Map.Map N.Name Type -> Extension -> Diff D.Doc
479−diffRecord dict fields1 ext1 fields2 ext2 =
469+diffRecord :: L.Localizer -> Map.Map N.Name Type -> Extension -> Map.Map N.Name Type -> Extension -> Diff D.Doc
470+diffRecord localizer fields1 ext1 fields2 ext2 =
480471 let
481472 only1 = Map.keys (Map.difference fields1 fields2)
482473 only2 = Map.keys (Map.difference fields2 fields1)
483474 in
484475 if null only1 && null only2 then
485− case findBadOverlaps dict fields1 fields2 of
476+ case findBadOverlaps localizer fields1 fields2 of
486477 [] ->
487478 case diffExt ext1 ext2 of
488479 Similar _ _ ->
@@ -602,10 +593,10 @@ data BadOverlap =
602593 }
603594
604595
605−findBadOverlaps :: Localizer -> Map.Map N.Name Type -> Map.Map N.Name Type -> [BadOverlap]
606−findBadOverlaps dict fields1 fields2 =
596+findBadOverlaps :: L.Localizer -> Map.Map N.Name Type -> Map.Map N.Name Type -> [BadOverlap]
597+findBadOverlaps localizer fields1 fields2 =
607598 findBadOverlapsHelp [] $ Map.toList $
608− Map.intersectionWith (diff dict RT.None) fields1 fields2
599+ Map.intersectionWith (diff localizer RT.None) fields1 fields2
609600
610601
611602findBadOverlapsHelp :: [BadOverlap] -> [(N.Name, Diff D.Doc)] -> [BadOverlap]
compiler/src/Type/Solve.hs+2−1
@@ -17,6 +17,7 @@ import qualified Elm.Name as N
1717import qualified Reporting.Annotation as A
1818import qualified Reporting.Error.Type as Error
1919import qualified Reporting.Render.Type as RT
20+import qualified Reporting.Render.Type.Localizer as L
2021import qualified Type.Occurs as Occurs
2122import Type.Type as Type
2223import qualified Type.Error as ET
@@ -203,7 +204,7 @@ isGeneric var =
203204 do tipe <- Type.toErrorType var
204205 error $
205206 "You ran into a compiler bug. Here are some details for the developers:\n\n"
206− ++ " " ++ show (ET.toDoc Map.empty RT.None tipe) ++ " [rank = " ++ show rank ++ "]\n\n"
207+ ++ " " ++ show (ET.toDoc L.empty RT.None tipe) ++ " [rank = " ++ show rank ++ "]\n\n"
207208 ++
208209 "Please create an <http://sscce.org/> and then report it\n\
209210 \at <https://github.com/elm-lang/elm-compiler/issues>\n\n"