@@ -68,7 +68,7 @@ data Error
6868 | PortPayloadInvalid A.Region Name.Name Can.Type InvalidPayload
6969 | PortTypeInvalid A.Region Name.Name PortProblem
7070 | RecursiveAlias A.Region Name.Name [Name.Name] Src.Type [Name.Name]
71− | RecursiveDecl [Can.Def]
71+ | RecursiveDecl A.Region Name.Name [Name.Name]
7272 | RecursiveLet (A.Located Name.Name) [Name.Name]
7373 | Shadowing Name.Name A.Region A.Region
7474 | TupleLargerThanThree A.Region
@@ -668,64 +668,51 @@ toReport source err =
668668 RecursiveAlias region name args tipe others ->
669669 aliasRecursionReport source region name args tipe others
670670
671− RecursiveDecl cyclicValueDefs ->
671+ RecursiveDecl region name names ->
672672 let
673− toName def =
674− case def of
675− Can.Def name _ _ -> name
676− Can.TypedDef name _ _ _ _ -> name
677−
678673 makeTheory question details =
679674 D.fillSep $ map (D.dullyellow . D.fromChars) (words question) ++ map D.fromChars (words details)
680675 in
681− case map toName cyclicValueDefs of
682− [] ->
683− error
684− "There is some compiler bug in reporting cyclic definitions.\n\
685− \Please get a <http://sscce.org/> and share the details at\n\
686− \<https://github.com/elm/compiler/issues>"
687−
688− A.At region name : otherNames ->
689− Report.Report "CYCLIC DEFINITION" region [] $
690− Report.toCodeSnippet source region Nothing $
691− case map A.toValue otherNames of
692− [] ->
693− (
694− D.reflow $
695− "The `" <> Name.toChars name <> "` value is defined directly in terms of itself, causing an infinite loop."
696− ,
697− D.stack
698− [ makeTheory "Are you are trying to mutate a variable?" $
699− "Elm does not have mutation, so when I see " ++ Name.toChars name
700− ++ " defined in terms of " ++ Name.toChars name
701− ++ ", I treat it as a recursive definition. Try giving the new value a new name!"
702− , makeTheory "Maybe you DO want a recursive value?" $
703− "To define " ++ Name.toChars name ++ " we need to know what " ++ Name.toChars name
704− ++ " is, so let’s expand it. Wait, but now we need to know what " ++ Name.toChars name
705− ++ " is, so let’s expand it... This will keep going infinitely!"
706− , D.link "Hint"
707− "The root problem is often a typo in some variable name, but I recommend reading"
708− "bad-recursion"
709− "for more detailed advice, especially if you actually do need a recursive value."
710− ]
711− )
676+ Report.Report "CYCLIC DEFINITION" region [] $
677+ Report.toCodeSnippet source region Nothing $
678+ case names of
679+ [] ->
680+ (
681+ D.reflow $
682+ "The `" <> Name.toChars name <> "` value is defined directly in terms of itself, causing an infinite loop."
683+ ,
684+ D.stack
685+ [ makeTheory "Are you are trying to mutate a variable?" $
686+ "Elm does not have mutation, so when I see " ++ Name.toChars name
687+ ++ " defined in terms of " ++ Name.toChars name
688+ ++ ", I treat it as a recursive definition. Try giving the new value a new name!"
689+ , makeTheory "Maybe you DO want a recursive value?" $
690+ "To define " ++ Name.toChars name ++ " we need to know what " ++ Name.toChars name
691+ ++ " is, so let’s expand it. Wait, but now we need to know what " ++ Name.toChars name
692+ ++ " is, so let’s expand it... This will keep going infinitely!"
693+ , D.link "Hint"
694+ "The root problem is often a typo in some variable name, but I recommend reading"
695+ "bad-recursion"
696+ "for more detailed advice, especially if you actually do need a recursive value."
697+ ]
698+ )
712699
713− names ->
714− (
715− D.reflow $
716− "The `" <> Name.toChars name <> "` definition is causing a very tricky infinite loop."
717− ,
718− D.stack
719− [ D.reflow $
720− "The `" <> Name.toChars name
721− <> "` value depends on itself through the following chain of definitions:"
722− , D.cycle 4 (name:names)
723− , D.link "Hint"
724− "The root problem is often a typo in some variable name, but I recommend reading"
725− "bad-recursion"
726− "for more detailed advice, especially if you actually do want mutually recursive values."
727− ]
728− )
700+ _:_ ->
701+ (
702+ D.reflow $
703+ "The `" <> Name.toChars name <> "` definition is causing a very tricky infinite loop."
704+ ,
705+ D.stack
706+ [ D.reflow $
707+ "The `" <> Name.toChars name
708+ <> "` value depends on itself through the following chain of definitions:"
709+ , D.cycle 4 name names
710+ , D.link "Hint"
711+ "The root problem is often a typo in some variable name, but I recommend reading"
712+ "bad-recursion"
713+ "for more detailed advice, especially if you actually do want mutually recursive values."
714+ ]
715+ )
729716
730717 RecursiveLet (A.At region name) names ->
731718 Report.Report "CYCLIC VALUE" region [] $
@@ -765,7 +752,7 @@ toReport source err =
765752 [ D.reflow $
766753 "The `" <> Name.toChars name
767754 <> "` value depends on itself through the following chain of definitions:"
768− , D.cycle 4 (name:names)
755+ , D.cycle 4 name names
769756 , D.link "Hint"
770757 "The root problem is often a typo in some variable name, but I recommend reading"
771758 "bad-recursion"
@@ -1252,7 +1239,7 @@ aliasRecursionReport source region name args tipe others =
12521239 ,
12531240 D.stack
12541241 [ "It is part of this cycle of type aliases:"
1255− , D.cycle 4 (name:others)
1242+ , D.cycle 4 name others
12561243 , D.reflow $
12571244 "You need to convert at least one of these type aliases into a `type`."
12581245 , D.link "Note" "Read" "recursive-alias"