@@ -3,7 +3,7 @@ module Reporting.Error.Canonicalize where
33
44import Control.Arrow (second)
55import qualified Data.Char as Char
6−import Text.PrettyPrint.ANSI.Leijen (indent, text)
6+import Text.PrettyPrint.ANSI.Leijen (Doc, dullyellow, fillSep, indent, text, vcat)
77
88import qualified AST.Expression.Canonical as Canonical
99import qualified AST.Module.Name as ModuleName
@@ -354,18 +354,24 @@ badSelfRecursion region name =
354354 in
355355 Report.report "BAD RECURSION" (Just region) header $
356356 Help.stack
357− [ Help.reflowParagraph $
358− "To define " ++ Help.functionName name ++ " we need to know what "
359− ++ Help.functionName name ++ " is, so let’s just expand that!\
360− \ Wait, but now we need to know what " ++ Help.functionName name
361− ++ " is, so let’s expand that..."
362− , Help.reflowParagraph $
363− "Check out the following links for more info on this situation and how to fix it: "
364− ++ Help.hintLink "bad-recursion"
365− ++ " <http://package.elm-lang.org/packages/elm-lang/core/latest/Json-Decode#lazy>"
357+ [ badSelfRecursionHelp "Maybe you are trying to mutate a variable?" $
358+ "Elm does not have mutation, so when I see " ++ Help.functionName name
359+ ++ " defined in terms of " ++ Help.functionName name
360+ ++ ", I treat it as a recursive definition. Try giving the new value a new name!"
361+ , badSelfRecursionHelp "Maybe you DO want a recursive value?" $
362+ "To define " ++ Help.functionName name ++ " we need to know what " ++ Help.functionName name
363+ ++ " is, so let’s expand it. Wait, but now we need to know what " ++ Help.functionName name
364+ ++ " is, so let’s expand it... This will keep going infinitely!"
365+ , badSelfRecursionHelp "To really learn what is going on and how to fix it, check out:" $
366+ Help.hintLink "bad-recursion"
366367 ]
367368
368369
370+badSelfRecursionHelp :: String -> String -> Doc
371+badSelfRecursionHelp intro body =
372+ fillSep $ map (dullyellow . text) (words intro) ++ map text (words body)
373+
374+
369375badMutualRecursion :: Region.Region -> String -> [String] -> Report.Report
370376badMutualRecursion region name names =
371377 let
@@ -384,15 +390,9 @@ badMutualRecursion region name names =
384390 "The following definitions depend directly on each other:"
385391 , indent 4 $ Help.drawCycle (name : names)
386392 , Help.reflowParagraph $
387− "So to define " ++ Help.functionName name
388− ++ " we go through " ++ otherDefs ++ " before needing to know what "
389− ++ Help.functionName name
390− ++ " is. We can expand it again, but then we need to know what "
391− ++ Help.functionName name ++ " is... This will keep going infinitely!"
392− , Help.reflowParagraph $
393− "Check out the following links for more info on this situation and how to fix it: "
393+ "You seem to have a fairly tricky case, so I very highly recommend reading this: "
394394 ++ Help.hintLink "bad-recursion"
395− ++ " <http://package.elm-lang.org/packages/elm-lang/core/latest/Json-Decode#lazy>"
395+ ++ " It will help you really understand the problem and how to fix it. Read it!"
396396 ]
397397
398398