on master help sign in
Actually draw a loop for mutually recursive type aliases
b0e91a4Evan Czaplicki
src/Reporting/Error/Canonicalize.hs+7−7
@@ -176,9 +176,9 @@ toReport localizer err =
176 "This type alias is recursive, forming an infinite type!"
176 "This type alias is recursive, forming an infinite type!"
177 (
177 (
178 Help.stack
178 Help.stack
179− [ text $
179+ [ Help.reflowParagraph $
180− "When I expand a recursive type alias, it just keeps getting bigger and bigger.\n"
180+ "When I expand a recursive type alias, it just keeps getting bigger and bigger.\
181− ++ "So dealiasing results in an infinitely large type! Try this instead:"
181+ \ So dealiasing results in an infinitely large type! Try this instead:"
182 , indent 4 $
182 , indent 4 $
183 RenderType.decl localizer name tvars [(name, [unsafePromote tipe])]
183 RenderType.decl localizer name tvars [(name, [unsafePromote tipe])]
184 , text $
184 , text $
@@ -194,10 +194,10 @@ toReport localizer err =
194 "This type alias is part of a mutually recursive set of type aliases."
194 "This type alias is part of a mutually recursive set of type aliases."
195 ( Help.stack
195 ( Help.stack
196 [ text "The following type aliases are mutually recursive:"
196 [ text "The following type aliases are mutually recursive:"
197− , error "TODO visual loop" aliases
197+ , Help.drawCycle (map (\(_, name, _, _) -> name) aliases)
198− , text $
198+ , Help.reflowParagraph $
199− "You need to convert at least one `type alias` into a `type`. This is a kind of\n"
199+ "You need to convert at least one `type alias` into a `type`. This is a kind of\
200− ++ "subtle distinction, so definitely read more about it here:\n"
200+ \ subtle distinction, so definitely read how to fix it and have great code:"
201 ++ Help.hintLink "infinite-alias"
201 ++ Help.hintLink "infinite-alias"
202 ]
202 ]
203 )
203 )
src/Reporting/Error/Helpers.hs+22−2
@@ -2,7 +2,7 @@
2module Reporting.Error.Helpers
2module Reporting.Error.Helpers
3 ( (|>)
3 ( (|>)
4 , functionName, hintLink, stack, reflowParagraph
4 , functionName, hintLink, stack, reflowParagraph
5− , commaSep, capitalize, ordinalize
5+ , commaSep, capitalize, ordinalize, drawCycle
6 , nearbyNames, distance, maybeYouWant
6 , nearbyNames, distance, maybeYouWant
7 )
7 )
8 where
8 where
@@ -11,7 +11,8 @@ import Data.Function (on)
11import qualified Data.Char as Char
11import qualified Data.Char as Char
12import qualified Data.List as List
12import qualified Data.List as List
13import qualified Text.EditDistance as Dist
13import qualified Text.EditDistance as Dist
14−import Text.PrettyPrint.ANSI.Leijen (Doc, (<>), fillSep, hardline, text)
14+import Text.PrettyPrint.ANSI.Leijen
15+ ( Doc, (<>), dullyellow, fillSep, hardline, text, vcat )
15
16
16import qualified AST.Helpers as Help
17import qualified AST.Helpers as Help
17import qualified Elm.Compiler.Version as Compiler
18import qualified Elm.Compiler.Version as Compiler
@@ -106,6 +107,25 @@ ordinalize number =
106
107
107
108
108
109
110+drawCycle :: [String] -> Doc
111+drawCycle strings =
112+ let
113+ topLine =
114+ text "┌─────┐"
115+
116+ line str =
117+ text "│ " <> dullyellow (text str)
118+
119+ midLine =
120+ text "│ ↓"
121+
122+ bottomLine =
123+ text "└─────┘"
124+ in
125+ vcat (topLine : List.intersperse midLine (map line strings) ++ [ bottomLine ])
126+
127+
128+
109-- NEARBY NAMES
129-- NEARBY NAMES
110
130
111
131