on master help sign in
Actually draw a loop for mutually recursive type aliases
commitb0e91a488148ba2bbea53bf2be86053b76d83b9c authorEvan Czaplicki <info@elm-lang.org> dateThu 22 Oct 2015, 01:04 (11 years ago) parent262a293
2 files changed+29−9
src/Reporting/Error/Canonicalize.hs+7−7 src/Reporting/Error/Helpers.hs+22−2
src/Reporting/Error/Canonicalize.hs+7−7
@@ -176,9 +176,9 @@ toReport localizer err =
176176 "This type alias is recursive, forming an infinite type!"
177177 (
178178 Help.stack
179− [ text $
180− "When I expand a recursive type alias, it just keeps getting bigger and bigger.\n"
181− ++ "So dealiasing results in an infinitely large type! Try this instead:"
179+ [ Help.reflowParagraph $
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:"
182182 , indent 4 $
183183 RenderType.decl localizer name tvars [(name, [unsafePromote tipe])]
184184 , text $
@@ -194,10 +194,10 @@ toReport localizer err =
194194 "This type alias is part of a mutually recursive set of type aliases."
195195 ( Help.stack
196196 [ text "The following type aliases are mutually recursive:"
197− , error "TODO visual loop" aliases
198− , text $
199− "You need to convert at least one `type alias` into a `type`. This is a kind of\n"
200− ++ "subtle distinction, so definitely read more about it here:\n"
197+ , Help.drawCycle (map (\(_, name, _, _) -> name) aliases)
198+ , Help.reflowParagraph $
199+ "You need to convert at least one `type alias` into a `type`. This is a kind of\
200+ \ subtle distinction, so definitely read how to fix it and have great code:"
201201 ++ Help.hintLink "infinite-alias"
202202 ]
203203 )
src/Reporting/Error/Helpers.hs+22−2
@@ -2,7 +2,7 @@
22module Reporting.Error.Helpers
33 ( (|>)
44 , functionName, hintLink, stack, reflowParagraph
5− , commaSep, capitalize, ordinalize
5+ , commaSep, capitalize, ordinalize, drawCycle
66 , nearbyNames, distance, maybeYouWant
77 )
88 where
@@ -11,7 +11,8 @@ import Data.Function (on)
1111import qualified Data.Char as Char
1212import qualified Data.List as List
1313import 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 )
1516
1617import qualified AST.Helpers as Help
1718import qualified Elm.Compiler.Version as Compiler
@@ -106,6 +107,25 @@ ordinalize number =
106107
107108
108109
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+
109129-- NEARBY NAMES
110130
111131