on master help sign in
Resolve final TODO that causes crashes in the compiler!
963a559Evan Czaplicki
src/Reporting/Error/Canonicalize.hs+57−1
@@ -649,7 +649,63 @@ toReport source err =
649 aliasRecursionReport source region name args tipe others
649 aliasRecursionReport source region name args tipe others
650
650
651 RecursiveDecl cyclicValueDefs ->
651 RecursiveDecl cyclicValueDefs ->
652− error "TODO" cyclicValueDefs
652+ let
653+ toName def =
654+ case def of
655+ Can.Def name _ _ -> name
656+ Can.TypedDef name _ _ _ _ -> name
657+
658+ makeTheory question details =
659+ H.fillSep $ map (H.dullyellow . H.text) (words question) ++ map H.text (words details)
660+ in
661+ case map toName cyclicValueDefs of
662+ [] ->
663+ error
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>"
667+
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
672+ [] ->
673+ (
674+ H.reflow $
675+ "The `" <> N.toString name <> "` value is defined directly in terms of itself, causing an infinite loop."
676+ ,
677+ H.stack
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!"
686+ , H.link "Hint"
687+ "The root problem is often a typo in some variable name, but I recommend reading"
688+ "bad-recursion"
689+ "for more detailed advice, especially if you actually do need a recursive value."
690+ ]
691+ )
692+
693+ names ->
694+ (
695+ H.reflow $
696+ "The `" <> N.toString name <> "` definition is causing a very tricky infinite loop."
697+ ,
698+ H.stack
699+ [ H.reflow $
700+ "The `" <> N.toString name
701+ <> "` value depends on itself through the following chain of definitions:"
702+ , H.indent 4 $ H.drawCycle (name:names)
703+ , H.link "Hint"
704+ "The root problem is often a typo in some variable name, but I recommend reading"
705+ "bad-recursion"
706+ "for more detailed advice, especially if you actually do want mutually recursive values."
707+ ]
708+ )
653
709
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 [] $