@@ -1,22 +1,32 @@
1{-# OPTIONS_GHC -Wall #-}
1{-# OPTIONS_GHC -Wall #-}
2+{-# LANGUAGE OverloadedStrings #-}
2−module Reporting.Error.Type where
3+module Reporting.Error.Type
5+ , Mismatch(..), Hint(..)
6+ , Reason(..), VarType(..)
4import Control.Arrow (first, second)
13import Control.Arrow (first, second)
5−import qualified Data.List as List
6import qualified Data.Map as Map
14import qualified Data.Map as Map
7import qualified Data.Maybe as Maybe
15import qualified Data.Maybe as Maybe
8−import Text.PrettyPrint.ANSI.Leijen
16+import qualified Data.Text as Text
9− ( Doc, (<>), (<+>), colon, dullyellow
17+import Data.Text (Text)
10− , fillSep, indent, text, underline, vcat
13import qualified AST.Helpers as Help
19import qualified AST.Helpers as Help
14import qualified AST.Type as Type
20import qualified AST.Type as Type
15import qualified AST.Variable as Var
21import qualified AST.Variable as Var
16−import qualified Reporting.Error.Helpers as Help
17import qualified Reporting.Region as Region
22import qualified Reporting.Region as Region
18import qualified Reporting.Render.Type as RenderType
23import qualified Reporting.Render.Type as RenderType
19import qualified Reporting.Report as Report
24import qualified Reporting.Report as Report
25+import qualified Reporting.Helpers as Help
26+import Reporting.Helpers
27+ ( Doc, (<>), (<+>), capitalize, colon, dullyellow, fillSep, functionName
28+ , i2t, indent, ordinalize, reflowParagraph, stack, text, underline, vcat
@@ -26,8 +36,8 @@ import qualified Reporting.Report as Report
27 = Mismatch Mismatch
37 = Mismatch Mismatch
28 | BadMain Type.Canonical
38 | BadMain Type.Canonical
29− | BadFlags Type.Canonical (Maybe String)
39+ | BadFlags Type.Canonical (Maybe Text)
30− | InfiniteType String Type.Canonical
40+ | InfiniteType Text Type.Canonical
33data Mismatch = MismatchInfo
43data Mismatch = MismatchInfo
@@ -39,8 +49,8 @@ data Mismatch = MismatchInfo
41data Reason
51data Reason
42− = BadFields [(String, Maybe Reason)]
52+ = BadFields [(Text, Maybe Reason)]
43− | MessyFields [String] [String] [String]
53+ | MessyFields [Text] [Text] [Text]
44 | IntFloat
54 | IntFloat
45 | TooLongComparableTuple Int
55 | TooLongComparableTuple Int
46 | MissingArgs Int
56 | MissingArgs Int
@@ -52,7 +62,7 @@ data VarType
52 | Comparable
62 | Comparable
53 | Appendable
63 | Appendable
54 | CompAppend
64 | CompAppend
55− | Rigid (Maybe String)
65+ | Rigid (Maybe Text)
@@ -70,24 +80,24 @@ data Hint
70 | Function (Maybe Var.Canonical)
80 | Function (Maybe Var.Canonical)
71 | UnexpectedArg (Maybe Var.Canonical) Int Int Region.Region
81 | UnexpectedArg (Maybe Var.Canonical) Int Int Region.Region
72 | FunctionArity (Maybe Var.Canonical) Int Int Region.Region
82 | FunctionArity (Maybe Var.Canonical) Int Int Region.Region
73− | ReturnType String Int Int Region.Region
83+ | ReturnType Text Int Int Region.Region
74− | Instance String
84+ | Instance Text
75− | Literal String
85+ | Literal Text
76 | Pattern Pattern
86 | Pattern Pattern
79− | Access (Maybe String) String
89+ | Access (Maybe Text) Text
81 -- effect manager problems
91 -- effect manager problems
82− | Manager String
92+ | Manager Text
83− | State String
93+ | State Text
87data Pattern
97data Pattern
88− = PVar String
98+ = PVar Text
89− | PAlias String
99+ | PAlias Text
90− | PData String
100+ | PCtor Var.Canonical
91 | PRecord
101 | PRecord
@@ -109,8 +119,8 @@ toReport localizer err =
109 "BAD MAIN TYPE"
119 "BAD MAIN TYPE"
111 "The `main` value has an unsupported type."
121 "The `main` value has an unsupported type."
112− ( Help.stack
122+ ( stack
113− [ Help.reflowParagraph $
123+ [ reflowParagraph $
114 "I need Html, Svg, or a Program so I have something to render on\
124 "I need Html, Svg, or a Program so I have something to render on\
115 \ screen, but you gave me:"
125 \ screen, but you gave me:"
116 , indent 4 (RenderType.toDoc localizer tipe)
126 , indent 4 (RenderType.toDoc localizer tipe)
@@ -120,24 +130,25 @@ toReport localizer err =
120 BadFlags tipe maybeMessage ->
130 BadFlags tipe maybeMessage ->
122 context =
132 context =
123− maybe "" (" the following " ++ ) maybeMessage
133+ maybe "" (" the following " <> ) maybeMessage
125 Report.report
135 Report.report
126 "BAD FLAGS"
136 "BAD FLAGS"
128 ("Your `main` is demanding an unsupported type as a flag."
138 ("Your `main` is demanding an unsupported type as a flag."
130− ( Help.stack
140+ ( stack
131− [ text ("The specific unsupported type is" ++ context ++ ":")
141+ [ text ("The specific unsupported type is" <> context <> ":")
132 , indent 4 (RenderType.toDoc localizer tipe)
142 , indent 4 (RenderType.toDoc localizer tipe)
133 , text "The types of values that can flow through in and out of Elm include:"
143 , text "The types of values that can flow through in and out of Elm include:"
134− , indent 4 $ Help.reflowParagraph $
144+ , indent 4 $ reflowParagraph $
135 "Ints, Floats, Bools, Strings, Maybes, Lists, Arrays,\
145 "Ints, Floats, Bools, Strings, Maybes, Lists, Arrays,\
136 \ Tuples, Json.Values, and concrete records."
146 \ Tuples, Json.Values, and concrete records."
141-- TYPE MISMATCHES
152-- TYPE MISMATCHES
@@ -152,18 +163,18 @@ mismatchToReport localizer (MismatchInfo hint leftType rightType maybeReason) =
153 cmpHint leftWords rightWords extraHints =
164 cmpHint leftWords rightWords extraHints =
154 comparisonHint localizer leftType rightType leftWords rightWords
165 comparisonHint localizer leftType rightType leftWords rightWords
155− (typicalHints ++ map toHint extraHints)
166+ (typicalHints <> map toHint extraHints)
157 case hint of
168 case hint of
158 CaseBranch branchNumber region ->
169 CaseBranch branchNumber region ->
160 (Just region)
171 (Just region)
161− ( "The " ++ ordinalPair branchNumber
172+ ( "The " <> ordinalPair branchNumber
162− ++ " branches of this `case` produce different types of values."
173+ <> " branches of this `case` produce different types of values."
164 ( cmpHint
175 ( cmpHint
165− ("The " ++ Help.ordinalize (branchNumber -1) ++ " branch has this type:")
176+ ("The " <> ordinalize (branchNumber - 1) <> " branch has this type:")
166− ("But the " ++ Help.ordinalize branchNumber ++ " is:")
177+ ("But the " <> ordinalize branchNumber <> " is:")
167 [ "All branches in a `case` must have the same type. So no matter\
178 [ "All branches in a `case` must have the same type. So no matter\
168 \ which one we take, we always get back the same type of value."
179 \ which one we take, we always get back the same type of value."
@@ -173,7 +184,7 @@ mismatchToReport localizer (MismatchInfo hint leftType rightType maybeReason) =
175 ( "All the branches of this case-expression are consistent, but the overall\n"
186 ( "All the branches of this case-expression are consistent, but the overall\n"
176− ++ "type does not match how it is used elsewhere."
187+ <> "type does not match how it is used elsewhere."
178 ( cmpHint
189 ( cmpHint
179 "The `case` evaluates to something of type:"
190 "The `case` evaluates to something of type:"
@@ -208,12 +219,12 @@ mismatchToReport localizer (MismatchInfo hint leftType rightType maybeReason) =
208 MultiIfBranch branchNumber region ->
219 MultiIfBranch branchNumber region ->
210 (Just region)
221 (Just region)
211− ( "The " ++ ordinalPair branchNumber
222+ ( "The " <> ordinalPair branchNumber
212− ++ " branches of this `if` produce different types of values."
223+ <> " branches of this `if` produce different types of values."
214 ( cmpHint
225 ( cmpHint
215− ("The " ++ Help.ordinalize (branchNumber - 1) ++ " branch has this type:")
226+ ("The " <> ordinalize (branchNumber - 1) <> " branch has this type:")
216− ("But the "++ Help.ordinalize branchNumber ++ " is:")
227+ ("But the "<> ordinalize branchNumber <> " is:")
217 [ "All the branches of an `if` need to match so that no matter which\
228 [ "All the branches of an `if` need to match so that no matter which\
218 \ one we take, we get back the same type of value overall."
229 \ one we take, we get back the same type of value overall."
@@ -233,10 +244,10 @@ mismatchToReport localizer (MismatchInfo hint leftType rightType maybeReason) =
233 ListElement elementNumber region ->
244 ListElement elementNumber region ->
235 (Just region)
246 (Just region)
236− ("The " ++ ordinalPair elementNumber ++ " entries in this list are different types of values.")
247+ ("The " <> ordinalPair elementNumber <> " entries in this list are different types of values.")
237 ( cmpHint
248 ( cmpHint
238− ("The " ++ Help.ordinalize (elementNumber - 1) ++ " entry has this type:")
249+ ("The " <> ordinalize (elementNumber - 1) <> " entry has this type:")
239− ("But the "++ Help.ordinalize elementNumber ++ " is:")
250+ ("But the "<> ordinalize elementNumber <> " is:")
240 [ "Every entry in a list needs to be the same type of value.\
251 [ "Every entry in a list needs to be the same type of value.\
241 \ This way you never run into unexpected values partway through.\
252 \ This way you never run into unexpected values partway through.\
242 \ To mix different types in a single list, create a \"union type\" as\
253 \ To mix different types in a single list, create a \"union type\" as\
@@ -247,8 +258,8 @@ mismatchToReport localizer (MismatchInfo hint leftType rightType maybeReason) =
250− ( "All the elements in this list are the same type, but the overall\n"
261+ ( "All the elements in this list are the same type, but the overall\
251− ++ "type does not match how it is used elsewhere."
262+ \ type does not match how it is used elsewhere."
253 ( cmpHint
264 ( cmpHint
254 "The list has type:"
265 "The list has type:"
@@ -259,9 +270,9 @@ mismatchToReport localizer (MismatchInfo hint leftType rightType maybeReason) =
259 BinopLeft op region ->
270 BinopLeft op region ->
261 (Just region)
272 (Just region)
262− ("The left argument of " ++ prettyName op ++ " is causing a type mismatch.")
273+ ("The left argument of " <> varName op <> " is causing a type mismatch.")
263 ( cmpHint
274 ( cmpHint
264− (prettyName op ++ " is expecting the left argument to be a:")
275+ (varName op <> " is expecting the left argument to be a:")
265 "But the left argument is:"
276 "But the left argument is:"
266 (binopHint op leftType rightType)
277 (binopHint op leftType rightType)
@@ -269,13 +280,13 @@ mismatchToReport localizer (MismatchInfo hint leftType rightType maybeReason) =
269 BinopRight op region ->
280 BinopRight op region ->
271 (Just region)
282 (Just region)
272− ("The right side of " ++ prettyName op ++ " is causing a type mismatch.")
283+ ("The right side of " <> varName op <> " is causing a type mismatch.")
273 ( cmpHint
284 ( cmpHint
274− (prettyName op ++ " is expecting the right side to be a:")
285+ (varName op <> " is expecting the right side to be a:")
275 "But the right side is:"
286 "But the right side is:"
276 ( binopHint op leftType rightType
287 ( binopHint op leftType rightType
278− [ "With operators like " ++ prettyName op ++ " I always check the left\
289+ [ "With operators like " <> varName op <> " I always check the left\
279 \ side first. If it seems fine, I assume it is correct and check the right\
290 \ side first. If it seems fine, I assume it is correct and check the right\
280 \ side. So the problem may be in how the left and right arguments interact."
291 \ side. So the problem may be in how the left and right arguments interact."
@@ -285,7 +296,7 @@ mismatchToReport localizer (MismatchInfo hint leftType rightType maybeReason) =
285 Binop op ->
296 Binop op ->
288− ( "The two arguments to " ++ prettyName op ++
299+ ( "The two arguments to " <> varName op <>
289 " are fine, but the overall type of this expression\
300 " are fine, but the overall type of this expression\
290 \ does not match how it is used elsewhere."
301 \ does not match how it is used elsewhere."
@@ -298,7 +309,7 @@ mismatchToReport localizer (MismatchInfo hint leftType rightType maybeReason) =
298 Function maybeName ->
309 Function maybeName ->
301− ( "The return type of " ++ funcName maybeName ++ " is being used in unexpected ways."
312+ ( "The return type of " <> maybeFuncName maybeName <> " is being used in unexpected ways."
303 ( cmpHint
314 ( cmpHint
304 "The function results in this type of value:"
315 "The function results in this type of value:"
@@ -309,9 +320,9 @@ mismatchToReport localizer (MismatchInfo hint leftType rightType maybeReason) =
309 UnexpectedArg maybeName 1 1 region ->
320 UnexpectedArg maybeName 1 1 region ->
311 (Just region)
322 (Just region)
312− ("The argument to " ++ funcName maybeName ++ " is causing a mismatch.")
323+ ("The argument to " <> maybeFuncName maybeName <> " is causing a mismatch.")
313 ( cmpHint
324 ( cmpHint
314− (Help.capitalize (funcName maybeName) ++ " is expecting the argument to be:")
325+ (capitalize (maybeFuncName maybeName) <> " is expecting the argument to be:")
315 "But it is:"
326 "But it is:"
316 (functionHint maybeName)
327 (functionHint maybeName)
@@ -319,12 +330,12 @@ mismatchToReport localizer (MismatchInfo hint leftType rightType maybeReason) =
319 UnexpectedArg maybeName index _totalArgs region ->
330 UnexpectedArg maybeName index _totalArgs region ->
321 (Just region)
332 (Just region)
322− ( "The " ++ Help.ordinalize index ++ " argument to " ++ funcName maybeName
333+ ( "The " <> ordinalize index <> " argument to " <> maybeFuncName maybeName
323− ++ " is causing a mismatch."
334+ <> " is causing a mismatch."
325 ( cmpHint
336 ( cmpHint
326− ( Help.capitalize (funcName maybeName) ++ " is expecting the "
337+ ( capitalize (maybeFuncName maybeName) <> " is expecting the "
327− ++ Help.ordinalize index ++ " argument to be:"
338+ <> ordinalize index <> " argument to be:"
329 "But it is:"
340 "But it is:"
330 ( functionHint maybeName
341 ( functionHint maybeName
@@ -335,23 +346,23 @@ mismatchToReport localizer (MismatchInfo hint leftType rightType maybeReason) =
335 [ "I always figure out the type of arguments from left to right. If an argument\
346 [ "I always figure out the type of arguments from left to right. If an argument\
336 \ is acceptable when I check it, I assume it is \"correct\" in subsequent checks.\
347 \ is acceptable when I check it, I assume it is \"correct\" in subsequent checks.\
337 \ So the problem may actually be in how previous arguments interact with the "
348 \ So the problem may actually be in how previous arguments interact with the "
338− ++ Help.ordinalize index ++ "."
349+ <> ordinalize index <> "."
343 FunctionArity maybeName 0 actual region ->
354 FunctionArity maybeName 0 actual region ->
346− if actual == 1 then "an argument" else show actual ++ " arguments"
357+ if actual == 1 then "an argument" else i2t actual <> " arguments"
348 preHint =
359 preHint =
349 case maybeName of
360 case maybeName of
350 Nothing ->
361 Nothing ->
351− "You are giving " ++ arg ++ " to something that is not a function!"
362+ "You are giving " <> args <> " to something that is not a function!"
353 Just name ->
364 Just name ->
354− prettyName name ++ " is not a function, but you are giving it " ++ arg ++ "!"
365+ varName name <> " is not a function, but you are giving it " <> args <> "!"
357 (Just region)
368 (Just region)
@@ -361,8 +372,8 @@ mismatchToReport localizer (MismatchInfo hint leftType rightType maybeReason) =
361 FunctionArity maybeName expected actual region ->
372 FunctionArity maybeName expected actual region ->
363 (Just region)
374 (Just region)
364− ( Help.capitalize (funcName maybeName) ++ " is expecting "
375+ ( capitalize (maybeFuncName maybeName) <> " is expecting "
365− ++ Help.args expected ++ ", but was given " ++ show actual ++ "."
376+ <> Help.args expected <> ", but was given " <> i2t actual <> "."
367 (text "Maybe you forgot some parentheses? Or a comma?")
378 (text "Maybe you forgot some parentheses? Or a comma?")
@@ -370,9 +381,9 @@ mismatchToReport localizer (MismatchInfo hint leftType rightType maybeReason) =
370 if typeArity == 0 || argArity == 0 then
381 if typeArity == 0 || argArity == 0 then
372 (Just region)
383 (Just region)
373− ("The definition of " ++ Help.functionName name ++ " does not match its type annotation.")
384+ ("The definition of " <> functionName name <> " does not match its type annotation.")
374 ( cmpHint
385 ( cmpHint
375− ( "The type annotation for " ++ Help.functionName name ++ " says it is a:"
386+ ( "The type annotation for " <> functionName name <> " says it is a:"
377 "But the definition (shown above) is a:"
388 "But the definition (shown above) is a:"
378 (arityHint typeArity argArity)
389 (arityHint typeArity argArity)
@@ -381,20 +392,24 @@ mismatchToReport localizer (MismatchInfo hint leftType rightType maybeReason) =
383 (Just region)
394 (Just region)
384− ("The definition of " ++ Help.functionName name ++ " does not match its type annotation.")
395+ ("The definition of " <> functionName name <> " does not match its type annotation.")
385 ( cmpHint
396 ( cmpHint
386− ( "The type annotation for " ++ Help.functionName name ++ " says it always returns:"
397+ ( "The type annotation for " <> functionName name <> " says it always returns:"
388 "But the returned value (shown above) is a:"
399 "But the returned value (shown above) is a:"
389 (arityHint typeArity argArity)
400 (arityHint typeArity argArity)
392− Instance name ->
403+ Instance var ->
395− (Help.functionName name ++ " is being used in an unexpected way.")
410+ (name <> " is being used in an unexpected way.")
396 ( cmpHint
411 ( cmpHint
397− ("Based on its definition, " ++ Help.functionName name ++ " has this type:")
412+ ("Based on its definition, " <> name <> " has this type:")
398 "But you are trying to use it as:"
413 "But you are trying to use it as:"
@@ -402,10 +417,10 @@ mismatchToReport localizer (MismatchInfo hint leftType rightType maybeReason) =
402 Literal name ->
417 Literal name ->
405− ( "This " ++ name ++ " value is being used as if it is some other type of value."
420+ ( "This " <> name <> " value is being used as if it is some other type of value."
407 ( cmpHint
422 ( cmpHint
408− ("The " ++ name ++ " definitely has this type:")
423+ ("The " <> name <> " definitely has this type:")
409 ("But it is being used as:")
424 ("But it is being used as:")
@@ -414,15 +429,24 @@ mismatchToReport localizer (MismatchInfo hint leftType rightType maybeReason) =
416 case patErr of
431 case patErr of
417− PVar name -> "variable `" ++ name ++ "`"
433+ "variable `" <> name <> "`"
418− PAlias name -> "alias `" ++ name ++ "`"
435+ PAlias name ->
436+ "alias `" <> name <> "`"
419− PRecord -> "this record"
439+ "this record"
421− if Help.isTuple name then "this tuple" else "tag `" ++ name ++ "`"
441+ PCtor (Var.Canonical Var.BuiltIn name) | Help.isTuple name ->
445+ "tag `" <> Var.toText name <> "`"
425− ( Help.capitalize thing ++ " is causing problems in this pattern match."
449+ ( capitalize thing <> " is causing problems in this pattern match."
427 ( cmpHint
451 ( cmpHint
428 "The pattern matches things of type:"
452 "The pattern matches things of type:"
@@ -452,25 +476,23 @@ mismatchToReport localizer (MismatchInfo hint leftType rightType maybeReason) =
453 Access (Just body) field ->
477 Access (Just body) field ->
456− "`" ++ body ++ "` does not have a field named `" ++ field ++ "`."
479+ header = "`" <> body <> "` does not have a field named `" <> field <> "`."
458− report Nothing header $ Help.stack $
481+ report Nothing header $ stack $
459− [ Help.reflowParagraph $ "The type of `" ++ body ++ "` is:"
482+ [ reflowParagraph $ "The type of `" <> body <> "` is:"
460 , indent 4 $ dullyellow $ RenderType.toDoc localizer leftType
483 , indent 4 $ dullyellow $ RenderType.toDoc localizer leftType
461− , Help.reflowParagraph $ "Which does not contain a field named `" ++ field ++ "`."
484+ , reflowParagraph $ "Which does not contain a field named `" <> field <> "`."
463 ++ typicalHints
486 ++ typicalHints
465 Access Nothing field ->
488 Access Nothing field ->
468− "Cannot access a field named `" ++ field ++ "`."
490+ header = "Cannot access a field named `" <> field <> "`."
470− report Nothing header $ Help.stack $
492+ report Nothing header $ stack $
471− [ Help.reflowParagraph $ "You are trying to get `" ++ field ++ "` from a value with this type:"
493+ [ reflowParagraph $ "You are trying to get `" <> field <> "` from a value with this type:"
472 , indent 4 $ dullyellow $ RenderType.toDoc localizer leftType
494 , indent 4 $ dullyellow $ RenderType.toDoc localizer leftType
473− , Help.reflowParagraph $ "It is not in there!"
495+ , reflowParagraph $ "It is not in there!"
475 ++ typicalHints
497 ++ typicalHints
@@ -487,9 +509,9 @@ mismatchToReport localizer (MismatchInfo hint leftType rightType maybeReason) =
487 Manager name ->
509 Manager name ->
490− ("The `" ++ name ++ "` in your effect manager has a weird type.")
512+ ("The `" <> name <> "` in your effect manager has a weird type.")
491 ( cmpHint
513 ( cmpHint
492− ("Your `" ++ name ++ "` function has this type:")
514+ ("Your `" <> name <> "` function has this type:")
493 "But it needs to have a type like this:"
515 "But it needs to have a type like this:"
494 [ "You can read more about setting up effect managers properly here:\
516 [ "You can read more about setting up effect managers properly here:\
495 \ <http://guide.elm-lang.org/effect_managers/>"
517 \ <http://guide.elm-lang.org/effect_managers/>"
@@ -500,11 +522,11 @@ mismatchToReport localizer (MismatchInfo hint leftType rightType maybeReason) =
502 ( "Your effect manager creates a certain type of state with `init`, but your `"
524 ( "Your effect manager creates a certain type of state with `init`, but your `"
503− ++ name ++ "` function expects a different kind of state."
525+ <> name <> "` function expects a different kind of state."
505 ( cmpHint
527 ( cmpHint
506 "The state created by `init` has this type:"
528 "The state created by `init` has this type:"
507− ("But `" ++ name ++ "` expects state of this type:")
529+ ("But `" <> name <> "` expects state of this type:")
508 [ "Make the two state types match and you should be all set! More info here:\
530 [ "Make the two state types match and you should be all set! More info here:\
509 \ <http://guide.elm-lang.org/effect_managers/>"
531 \ <http://guide.elm-lang.org/effect_managers/>"
@@ -529,8 +551,8 @@ comparisonHint
529 :: RenderType.Localizer
551 :: RenderType.Localizer
530 -> Type.Canonical
552 -> Type.Canonical
531 -> Type.Canonical
553 -> Type.Canonical
532− -> String
554+ -> Text
533− -> String
555+ -> Text
536comparisonHint localizer leftType rightType leftWords rightWords finalHints =
558comparisonHint localizer leftType rightType leftWords rightWords finalHints =
@@ -538,10 +560,10 @@ comparisonHint localizer leftType rightType leftWords rightWords finalHints =
538 (leftDoc, rightDoc) =
560 (leftDoc, rightDoc) =
539 RenderType.diffToDocs localizer leftType rightType
561 RenderType.diffToDocs localizer leftType rightType
541− Help.stack $
563+ stack $
542− [ Help.reflowParagraph leftWords
564+ [ reflowParagraph leftWords
543 , indent 4 leftDoc
565 , indent 4 leftDoc
544− , Help.reflowParagraph rightWords
566+ , reflowParagraph rightWords
545 , indent 4 rightDoc
567 , indent 4 rightDoc
@@ -552,7 +574,7 @@ comparisonHint localizer leftType rightType leftWords rightWords finalHints =
552-- BINOP HINTS
574-- BINOP HINTS
555−binopHint :: Var.Canonical -> Type.Canonical -> Type.Canonical -> [String]
577+binopHint :: Var.Canonical -> Type.Canonical -> Type.Canonical -> [Text]
556binopHint op leftType rightType =
578binopHint op leftType rightType =
558 leftString =
580 leftString =
@@ -561,12 +583,12 @@ binopHint op leftType rightType =
561 rightString =
583 rightString =
562 show (RenderType.toDoc Map.empty rightType)
584 show (RenderType.toDoc Map.empty rightType)
564− if Var.is ["Basics"] "+" op && elem "String" [leftString, rightString] then
586+ if Var.is "Basics" "+" op && elem "String" [leftString, rightString] then
565− [ "To append strings in Elm, you need to use the (++) operator, not (+). "
587+ [ "To append strings in Elm, you need to use the (++) operator, not (+).\
566− ++ "<http://package.elm-lang.org/packages/elm-lang/core/latest/Basics#++>"
588+ \ <http://package.elm-lang.org/packages/elm-lang/core/latest/Basics#++>"
569− else if Var.is ["Basics"] "/" op && elem "Int" [leftString, rightString] then
591+ else if Var.is "Basics" "/" op && elem "Int" [leftString, rightString] then
570 [ "The (/) operator is specifically for floating point division, and (//) is\
592 [ "The (/) operator is specifically for floating point division, and (//) is\
571 \ for integer division. You may need to do some conversions between ints and\
593 \ for integer division. You may need to do some conversions between ints and\
572 \ floats to get both arguments matching the division operator you want."
594 \ floats to get both arguments matching the division operator you want."
@@ -580,14 +602,14 @@ binopHint op leftType rightType =
580-- FUNCTION HINTS
602-- FUNCTION HINTS
583−functionHint :: Maybe Var.Canonical -> [String]
605+functionHint :: Maybe Var.Canonical -> [Text]
584functionHint maybeName =
606functionHint maybeName =
585 case maybeName of
607 case maybeName of
586 Nothing ->
608 Nothing ->
589 Just name ->
611 Just name ->
590− if Var.inHtml ["Html","App"] "program" == name then
612+ if Var.inHtml "Html" "program" == name then
591 [ "Does your program have flags? Maybe you want `programWithFlags` instead."
613 [ "Does your program have flags? Maybe you want `programWithFlags` instead."
@@ -599,20 +621,21 @@ functionHint maybeName =
599-- ARITY HINTS
621-- ARITY HINTS
602−arityHint :: Int -> Int -> [String]
624+arityHint :: Int -> Int -> [Text]
603arityHint typeArity argArity =
625arityHint typeArity argArity =
604 if typeArity == argArity then
626 if typeArity == argArity then
608− [ "The type annotation says there " ++ sayArgs typeArity
630+ [ "The type annotation says there " <> sayArgs typeArity <>
609− ++ ", but there " ++ sayArgs argArity ++ " named in the definition."
631+ ", but there " <> sayArgs argArity <>
610− ++ " It is best practice for each argument in the type to correspond"
632+ " named in the definition. It is best practice for each argument\
611− ++ " to a named argument in the definition, so try that first!"
633+ \ in the type to correspond to a named argument in the definition,\
634+ \ so try that first!"
615−sayArgs :: Int -> String
638+sayArgs :: Int -> Text
616sayArgs n =
639sayArgs n =
617 case n of
640 case n of
@@ -622,31 +645,31 @@ sayArgs n =
622 "is 1 argument"
645 "is 1 argument"
625− "are " ++ show n ++ " arguments"
648+ "are " <> i2t n <> " arguments"
629-- MISMATCH HELPERS
652-- MISMATCH HELPERS
632−ordinalPair :: Int -> String
655+ordinalPair :: Int -> Text
633ordinalPair number =
656ordinalPair number =
634− Help.ordinalize (number -1 ) ++ " and " ++ Help.ordinalize number
657+ ordinalize (number - 1) <> " and " <> ordinalize number
637−prettyName :: Var.Canonical -> String
660+varName :: Var.Canonical -> Text
638−prettyName (Var.Canonical _ opName) =
661+varName (Var.Canonical _ opName) =
639− Help.functionName opName
662+ functionName opName
642−funcName :: Maybe Var.Canonical -> String
665+maybeFuncName :: Maybe Var.Canonical -> Text
643−funcName maybeVar =
666+maybeFuncName maybeVar =
644 case maybeVar of
667 case maybeVar of
645 Nothing ->
668 Nothing ->
646 "this function"
669 "this function"
648 Just var ->
671 Just var ->
649− "function " ++ prettyName var
672+ "function " <> varName var
@@ -690,26 +713,26 @@ reasonToString reason =
692 [field] ->
715 [field] ->
693− Just $ "Problem in the `" ++ field ++ "` field. "
716+ Just $ "Problem in the `" <> field <> "` field. "
696− Just $ "Problem at `" ++ List.intercalate "." fields ++ "`. "
719+ Just $ "Problem at `" <> Text.intercalate "." fields <> "`. "
698 case (starter, maybeDocs) of
721 case (starter, maybeDocs) of
699 (Nothing, Nothing) ->
722 (Nothing, Nothing) ->
702 (Just msg, Nothing) ->
725 (Just msg, Nothing) ->
703− Just $ toHint (msg ++ badFieldElaboration)
726+ Just $ toHint (msg <> badFieldElaboration)
705 (_, Just (firstLine, docs)) ->
728 (_, Just (firstLine, docs)) ->
706 Just $ vcat $
729 Just $ vcat $
707− toHint (maybe firstLine (++firstLine) starter)
730+ toHint (maybe firstLine (<> firstLine) starter)
708 : map (indent 4) docs
731 : map (indent 4) docs
712−collectFields :: Reason -> ([String], Maybe Reason)
735+collectFields :: Reason -> ([Text], Maybe Reason)
713collectFields reason =
736collectFields reason =
714 case reason of
737 case reason of
715 BadFields [(field, Nothing)] ->
738 BadFields [(field, Nothing)] ->
@@ -722,7 +745,7 @@ collectFields reason =
722 ([], Just reason)
745 ([], Just reason)
725−reasonToStringHelp :: Reason -> Maybe (String, [Doc])
748+reasonToStringHelp :: Reason -> Maybe (Text, [Doc])
726reasonToStringHelp reason =
749reasonToStringHelp reason =
@@ -732,8 +755,8 @@ reasonToStringHelp reason =
732 BadFields fields ->
755 BadFields fields ->
734 "I am seeing issues with the "
757 "I am seeing issues with the "
735− ++ Help.commaSep (map fst fields) ++ " fields. "
758+ <> Help.commaSep (map fst fields) <> " fields. "
736− ++ badFieldElaboration
759+ <> badFieldElaboration
738 MessyFields both leftOnly rightOnly ->
761 MessyFields both leftOnly rightOnly ->
739 messyFieldsHelp both leftOnly rightOnly
762 messyFieldsHelp both leftOnly rightOnly
@@ -747,12 +770,11 @@ reasonToStringHelp reason =
747 TooLongComparableTuple len ->
770 TooLongComparableTuple len ->
749 "Although tuples are comparable, this is currently only supported\
772 "Although tuples are comparable, this is currently only supported\
750− \ for tuples with 6 or fewer entries, not " ++ show len ++ "."
773+ \ for tuples with 6 or fewer entries, not " <> i2t len <> "."
752 MissingArgs num ->
775 MissingArgs num ->
754− "It looks like a function needs " ++ show num ++ " more "
777+ "It looks like a function needs " <> i2t num <> " more" <> Help.args num <> "."
755− ++ (if num == 1 then "argument" else "arguments") ++ "."
757 BadVar (Just Comparable) _ ->
779 BadVar (Just Comparable) _ ->
758 go "Only ints, floats, chars, strings, lists, and tuples are comparable."
780 go "Only ints, floats, chars, strings, lists, and tuples are comparable."
@@ -776,48 +798,48 @@ reasonToStringHelp reason =
779−badFieldElaboration :: String
801+badFieldElaboration :: Text
780badFieldElaboration =
802badFieldElaboration =
781 "I always figure out field types in alphabetical order. If a field\
803 "I always figure out field types in alphabetical order. If a field\
782 \ seems fine, I assume it is \"correct\" in subsequent checks.\
804 \ seems fine, I assume it is \"correct\" in subsequent checks.\
783 \ So the problem may actually be a weird interaction with previous fields."
805 \ So the problem may actually be a weird interaction with previous fields."
786−weirdRigidError :: String
808+weirdRigidError :: Text
787weirdRigidError =
809weirdRigidError =
788 "You are having a problem with \"rigid\" type variables. That usually\
810 "You are having a problem with \"rigid\" type variables. That usually\
789 \ means you have a type annotation that says it accepts anything, but\
811 \ means you have a type annotation that says it accepts anything, but\
790 \ in fact, it accepts a much more specific type. More info at: "
812 \ in fact, it accepts a much more specific type. More info at: "
791− ++ Help.hintLink "type-annotations" ++
813+ <> Help.hintLink "type-annotations" <>
792 ". This case is weird though, so please turn it into an <http://sscce.org>\
814 ". This case is weird though, so please turn it into an <http://sscce.org>\
793 \ and report it to <https://github.com/elm-lang/error-message-catalog>."
815 \ and report it to <https://github.com/elm-lang/error-message-catalog>."
796−singleRigidError :: Maybe String -> String
818+singleRigidError :: Maybe Text -> Text
797singleRigidError maybeName =
819singleRigidError maybeName =
798 case maybeName of
820 case maybeName of
799 Just name ->
821 Just name ->
800− "Your type annotation uses type variable `" ++ name ++
822+ "Your type annotation uses type variable `" <> name <>
801 "` which means any type of value can flow through. Your code is saying\
823 "` which means any type of value can flow through. Your code is saying\
802 \ it CANNOT be anything though! Maybe change your type annotation to\
824 \ it CANNOT be anything though! Maybe change your type annotation to\
803 \ be more specific? Maybe the code has a problem? More at: "
825 \ be more specific? Maybe the code has a problem? More at: "
804− ++ Help.hintLink "type-annotations"
826+ <> Help.hintLink "type-annotations"
806 Nothing ->
828 Nothing ->
807 weirdRigidError
829 weirdRigidError
810−doubleRigidError :: Maybe String -> Maybe String -> String
832+doubleRigidError :: Maybe Text -> Maybe Text -> Text
811doubleRigidError maybeLeftName maybeRightName =
833doubleRigidError maybeLeftName maybeRightName =
812 case (maybeLeftName, maybeRightName) of
834 case (maybeLeftName, maybeRightName) of
813 (Just leftName, Just rightName) ->
835 (Just leftName, Just rightName) ->
814− "Your type annotation uses `" ++ leftName ++ "` and `" ++ rightName ++
836+ "Your type annotation uses `" <> leftName <> "` and `" <> rightName <>
815 "` as separate type variables. Each one can be any type of value,\
837 "` as separate type variables. Each one can be any type of value,\
816 \ but because they have separate names, there is no guarantee that they\
838 \ but because they have separate names, there is no guarantee that they\
817 \ are equal to each other. Your code seems to be saying they ARE the\
839 \ are equal to each other. Your code seems to be saying they ARE the\
818 \ same though! Maybe they should be the same in your type annotation?\
840 \ same though! Maybe they should be the same in your type annotation?\
819 \ Maybe your code uses them in a weird way? More at: "
841 \ Maybe your code uses them in a weird way? More at: "
820− ++ Help.hintLink "type-annotations"
842+ <> Help.hintLink "type-annotations"
823 weirdRigidError
845 weirdRigidError
@@ -828,12 +850,12 @@ hintDoc =
828 underline (text "Hint") <> colon
850 underline (text "Hint") <> colon
831−toHint :: String -> Doc
853+toHint :: Text -> Doc
832−toHint str =
854+toHint txt =
833− fillSep (hintDoc : map text (words str))
855+ fillSep (hintDoc : map text (Text.words txt))
836−messyFieldsHelp :: [String] -> [String] -> [String] -> Maybe (String, [Doc])
858+messyFieldsHelp :: [Text] -> [Text] -> [Text] -> Maybe (Text, [Doc])
837messyFieldsHelp both leftOnly rightOnly =
859messyFieldsHelp both leftOnly rightOnly =
838 case (leftOnly, rightOnly) of
860 case (leftOnly, rightOnly) of
839 ([], [missingField]) ->
861 ([], [missingField]) ->
@@ -861,8 +883,8 @@ messyFieldsHelp both leftOnly rightOnly =
861 if null typoPairs then
883 if null typoPairs then
863 ( "The record fields do not match up. One has "
885 ( "The record fields do not match up. One has "
864− ++ Help.commaSep leftOnly ++ ". The other has "
886+ <> Help.commaSep leftOnly <> ". The other has "
865− ++ Help.commaSep rightOnly ++ "."
887+ <> Help.commaSep rightOnly <> "."
@@ -873,61 +895,62 @@ messyFieldsHelp both leftOnly rightOnly =
876−oneMissingField :: [String] -> String -> Maybe (String, [Doc])
898+oneMissingField :: [Text] -> Text -> Maybe (Text, [Doc])
877oneMissingField knownFields missingField =
899oneMissingField knownFields missingField =
878 case Help.findPotentialTypos knownFields missingField of
900 case Help.findPotentialTypos knownFields missingField of
881− ( "Looks like a record is missing the `" ++ missingField ++ "` field."
903+ ( "Looks like a record is missing the `" <> missingField <> "` field."
885 [typo] ->
907 [typo] ->
887− ( "Looks like a record is missing the `" ++ missingField
909+ ( "Looks like a record is missing the `" <> missingField
888− ++ "` field. Maybe it is a typo?"
910+ <> "` field. Maybe it is a typo?"
889 , typoDocs "->" [(missingField, typo)]
911 , typoDocs "->" [(missingField, typo)]
894− ( "Looks like a record is missing the `" ++ missingField
916+ ( "Looks like a record is missing the `" <> missingField
895− ++ "` field. It is close to names like "
917+ <> "` field. It is close to names like "
896− ++ Help.commaSep typos ++ " so maybe it is a typo?"
918+ <> Help.commaSep typos <> " so maybe it is a typo?"
901−manyMissingFields :: [String] -> [String] -> Maybe (String, [Doc])
923+manyMissingFields :: [Text] -> [Text] -> Maybe (Text, [Doc])
902manyMissingFields knownFields missingFields =
924manyMissingFields knownFields missingFields =
903 case Help.findTypoPairs missingFields knownFields of
925 case Help.findTypoPairs missingFields knownFields of
906 ( "Looks like a record is missing these fields: "
928 ( "Looks like a record is missing these fields: "
907− ++ Help.commaSep missingFields
929+ <> Help.commaSep missingFields
911 typoPairs ->
933 typoPairs ->
913− ( "Looks like a record is missing these fields: " ++ Help.commaSep missingFields
935+ ( "Looks like a record is missing these fields: "
936+ <> Help.commaSep missingFields
914− ++ ". Potential typos include:"
937+ <> ". Potential typos include:"
915 , typoDocs "->" typoPairs
938 , typoDocs "->" typoPairs
919−typoDocs :: String -> [(String, String)] -> [Doc]
942+typoDocs :: Text -> [(Text, Text)] -> [Doc]
920typoDocs arrow typoPairs =
943typoDocs arrow typoPairs =
923− maximum (map (length . fst) typoPairs)
946+ maximum (map (Text.length . fst) typoPairs)
925 text "" : map (padTypo arrow maxLen) typoPairs
948 text "" : map (padTypo arrow maxLen) typoPairs
928−padTypo :: String -> Int -> (String, String) -> Doc
951+padTypo :: Text -> Int -> (Text, Text) -> Doc
929padTypo arrow maxLen (missingField, knownField) =
952padTypo arrow maxLen (missingField, knownField) =
930− text (replicate (maxLen - length missingField) ' ')
953+ text (Text.replicate (maxLen - Text.length missingField) " ")
931 <> dullyellow (text missingField)
954 <> dullyellow (text missingField)
932 <+> text arrow
955 <+> text arrow
933 <+> dullyellow (text knownField)
956 <+> dullyellow (text knownField)
@@ -939,24 +962,23 @@ padTypo arrow maxLen (missingField, knownField) =
940infiniteTypeToReport
963infiniteTypeToReport
941 :: RenderType.Localizer
964 :: RenderType.Localizer
942− -> String
965+ -> Text
943 -> Type.Canonical
966 -> Type.Canonical
944 -> Report.Report
967 -> Report.Report
945infiniteTypeToReport localizer name overallType =
968infiniteTypeToReport localizer name overallType =
946 Report.report
969 Report.report
947 "INFINITE TYPE"
970 "INFINITE TYPE"
949− ( "I am inferring a weird self-referential type for " ++ Help.functionName name
972+ ( "I am inferring a weird self-referential type for " <> functionName name
951− ( Help.stack
974+ ( stack
952− [ Help.reflowParagraph $
975+ [ reflowParagraph $
953 "Here is my best effort at writing down the type. You will see ? and ∞ for\
976 "Here is my best effort at writing down the type. You will see ? and ∞ for\
954 \ parts of the type that repeat something already printed out infinitely."
977 \ parts of the type that repeat something already printed out infinitely."
955 , indent 4 (RenderType.toDoc localizer overallType)
978 , indent 4 (RenderType.toDoc localizer overallType)
956− , Help.reflowParagraph $
979+ , reflowParagraph $
957 "Usually staring at the type is not so helpful in these cases, so definitely\
980 "Usually staring at the type is not so helpful in these cases, so definitely\
958 \ read the debugging hints for ideas on how to figure this out: "
981 \ read the debugging hints for ideas on how to figure this out: "
959− ++ Help.hintLink "infinite-type"
982+ <> Help.hintLink "infinite-type"