@@ -649,7 +649,63 @@ toReport source err =
649 aliasRecursionReport source region name args tipe others
649 aliasRecursionReport source region name args tipe others
651 RecursiveDecl cyclicValueDefs ->
651 RecursiveDecl cyclicValueDefs ->
652− error "TODO" cyclicValueDefs
652+ let
655+ Can.Def name _ _ -> name
656+ Can.TypedDef name _ _ _ _ -> name
658+ makeTheory question details =
659+ H.fillSep $ map (H.dullyellow . H.text) (words question) ++ map H.text (words details)
661+ case map toName cyclicValueDefs of
664+ "There is some compiler bug in reporting cyclic definitions.\n\
665+ \Please get a <http://sscce.org/> and share the details at\n\
666+ \<https://github.com/elm-lang/elm-compiler/issues>"
668+ A.At region name : otherNames ->
669+ Report.Report "CYCLIC DEFINITION" region [] $
670+ Report.toCodeSnippet source region Nothing $
671+ case map A.toValue otherNames of
675+ "The `" <> N.toString name <> "` value is defined directly in terms of itself, causing an infinite loop."
678+ [ makeTheory "Are you are trying to mutate a variable?" $
679+ "Elm does not have mutation, so when I see " ++ N.toString name
680+ ++ " defined in terms of " ++ N.toString name
681+ ++ ", I treat it as a recursive definition. Try giving the new value a new name!"
682+ , makeTheory "Maybe you DO want a recursive value?" $
683+ "To define " ++ N.toString name ++ " we need to know what " ++ N.toString name
684+ ++ " is, so let’s expand it. Wait, but now we need to know what " ++ N.toString name
685+ ++ " is, so let’s expand it... This will keep going infinitely!"
687+ "The root problem is often a typo in some variable name, but I recommend reading"
689+ "for more detailed advice, especially if you actually do need a recursive value."
696+ "The `" <> N.toString name <> "` definition is causing a very tricky infinite loop."
700+ "The `" <> N.toString name
701+ <> "` value depends on itself through the following chain of definitions:"
702+ , H.indent 4 $ H.drawCycle (name:names)
704+ "The root problem is often a typo in some variable name, but I recommend reading"
706+ "for more detailed advice, especially if you actually do want mutually recursive values."
654 RecursiveLet (A.At region name) names ->
710 RecursiveLet (A.At region name) names ->
655 Report.Report "CYCLIC VALUE" region [] $
711 Report.Report "CYCLIC VALUE" region [] $