on master help sign in
Update a bunch of files based on Doc changes
b1fd35fEvan Czaplicki
builder/src/Deps/Get.hs+3−3
@@ -25,11 +25,11 @@ import qualified Text.PrettyPrint.ANSI.Leijen as P
25
25
26import qualified Elm.Docs as Docs
26import qualified Elm.Docs as Docs
27import qualified Elm.Package as Pkg
27import qualified Elm.Package as Pkg
28−import qualified Elm.Utils as Utils
29
28
30import qualified Deps.Website as Website
29import qualified Deps.Website as Website
31import qualified Elm.Project.Json as Project
30import qualified Elm.Project.Json as Project
32import qualified File.IO as IO
31import qualified File.IO as IO
32+import qualified Reporting.Suggest as Suggest
33import qualified Reporting.Exit as Exit
33import qualified Reporting.Exit as Exit
34import qualified Reporting.Exit.Assets as E
34import qualified Reporting.Exit.Assets as E
35import qualified Reporting.Progress as Progress
35import qualified Reporting.Progress as Progress
@@ -122,7 +122,7 @@ nearbyNames (Pkg.Name author1 project1) possibleNames =
122
122
123authorDistance :: String -> Text.Text -> Int
123authorDistance :: String -> Text.Text -> Int
124authorDistance bad possibility =
124authorDistance bad possibility =
125− abs (Utils.distance bad (Text.unpack possibility))
125+ abs (Suggest.distance bad (Text.unpack possibility))
126
126
127
127
128projectDistance :: String -> Text.Text -> Int
128projectDistance :: String -> Text.Text -> Int
@@ -130,7 +130,7 @@ projectDistance bad possibility =
130 if possibility == "elm-lang" || possibility == "elm-explorations" then
130 if possibility == "elm-lang" || possibility == "elm-explorations" then
131 0
131 0
132 else
132 else
133− abs (Utils.distance bad (Text.unpack possibility))
133+ abs (Suggest.distance bad (Text.unpack possibility))
134
134
135
135
136
136
builder/src/Elm/Project/Licenses.hs+2−2
@@ -13,8 +13,8 @@ import Data.Map ((!))
13import qualified Data.Map as Map
13import qualified Data.Map as Map
14import qualified Data.Text as Text
14import qualified Data.Text as Text
15
15
16−import qualified Elm.Utils as Utils
17import qualified Json.Encode as Encode
16import qualified Json.Encode as Encode
17+import qualified Reporting.Suggest as Suggest
18
18
19
19
20
20
@@ -61,7 +61,7 @@ check rawName =
61 Text.unpack suggestion
61 Text.unpack suggestion
62 in
62 in
63 Left $ map snd $
63 Left $ map snd $
64− Utils.nearbyNames toSuggestion (rawName, rawName) pairs
64+ Suggest.nearbyNames toSuggestion (rawName, rawName) pairs
65
65
66
66
67
67
builder/src/Reporting/Exit.hs+4−6
@@ -8,16 +8,14 @@ module Reporting.Exit
8 where
8 where
9
9
10
10
11−import qualified Data.ByteString.Builder as B
12import Data.Monoid ((<>))
11import Data.Monoid ((<>))
13−import System.IO (stderr)
14import qualified Text.PrettyPrint.ANSI.Leijen as P
12import qualified Text.PrettyPrint.ANSI.Leijen as P
15
13
16import qualified Elm.Compiler as Compiler
14import qualified Elm.Compiler as Compiler
17import qualified Elm.Compiler.Module as Module
15import qualified Elm.Compiler.Module as Module
18import qualified Elm.Package as Pkg
16import qualified Elm.Package as Pkg
19−import qualified Elm.Utils as Utils
20import qualified Json.Encode as Encode
17import qualified Json.Encode as Encode
18+import qualified Reporting.Doc as D
21import qualified Reporting.Exit.Assets as Asset
19import qualified Reporting.Exit.Assets as Asset
22import qualified Reporting.Exit.Bump as Bump
20import qualified Reporting.Exit.Bump as Bump
23import qualified Reporting.Exit.Compile as Compile
21import qualified Reporting.Exit.Compile as Compile
@@ -65,9 +63,9 @@ toStderr exit =
65 Help.toStderr (Help.reportToDoc (toReport exit))
63 Help.toStderr (Help.reportToDoc (toReport exit))
66
64
67
65
68−toJson :: Exit -> IO ()
66+toJson :: Exit -> Encode.Value
69toJson exit =
67toJson exit =
70− B.hPutBuilder stderr $ Encode.encodeUgly $ Help.reportToJson (toReport exit)
68+ Help.reportToJson (toReport exit)
71
69
72
70
73toReport :: Exit -> Help.Report
71toReport :: Exit -> Help.Report
@@ -106,7 +104,7 @@ toReport exit =
106 Cycle names ->
104 Cycle names ->
107 Help.report "IMPORT CYCLE" Nothing
105 Help.report "IMPORT CYCLE" Nothing
108 "Your module imports form a cycle:"
106 "Your module imports form a cycle:"
109− [ P.indent 4 (Utils.drawCycle names)
107+ [ D.cycle 4 names
110 , Help.reflow $
108 , Help.reflow $
111 "Learn more about why this is disallowed and how to break cycles here:"
109 "Learn more about why this is disallowed and how to break cycles here:"
112 ++ Help.hintLink "import-cycles"
110 ++ Help.hintLink "import-cycles"
compiler/src/Elm/Compiler.hs+5−10
@@ -16,15 +16,14 @@ module Elm.Compiler
16import qualified Data.ByteString as BS
16import qualified Data.ByteString as BS
17import qualified Data.Map as Map
17import qualified Data.Map as Map
18import qualified Data.Text as Text
18import qualified Data.Text as Text
19−import qualified Text.PrettyPrint.ANSI.Leijen as P
20
19
21import qualified Compile
20import qualified Compile
22import qualified Elm.Compiler.Module as M
21import qualified Elm.Compiler.Module as M
23import qualified Elm.Compiler.Version
22import qualified Elm.Compiler.Version
24import qualified Elm.Package as Pkg
23import qualified Elm.Package as Pkg
25import qualified Json.Encode as Encode
24import qualified Json.Encode as Encode
25+import qualified Reporting.Doc as D
26import qualified Reporting.Error as Error
26import qualified Reporting.Error as Error
27−import qualified Reporting.Helpers as H
28import qualified Reporting.Render.Code as Code
27import qualified Reporting.Render.Code as Code
29import qualified Reporting.Region as Region
28import qualified Reporting.Region as Region
30import qualified Reporting.Report as Report
29import qualified Reporting.Report as Report
@@ -63,13 +62,13 @@ compile (Context pkg docsFlag importDict interfaces) source =
63-- ERRORS TO DOC
62-- ERRORS TO DOC
64
63
65
64
66−errorsToDoc :: FilePath -> Text.Text -> [Error.Error] -> H.Doc
65+errorsToDoc :: FilePath -> Text.Text -> [Error.Error] -> D.Doc
67errorsToDoc filePath source errors =
66errorsToDoc filePath source errors =
68 let
67 let
69 reports =
68 reports =
70 concatMap (Error.toReports (Code.toSource source) Map.empty) errors
69 concatMap (Error.toReports (Code.toSource source) Map.empty) errors
71 in
70 in
72− H.vcat $ map (Report.toDoc filePath) reports
71+ D.vcat $ map (Report.toDoc filePath) reports
73
72
74
73
75
74
@@ -85,18 +84,14 @@ errorsToJson moduleName filePath source errors =
85 Encode.object
84 Encode.object
86 [ ("path", Encode.text (Text.pack filePath))
85 [ ("path", Encode.text (Text.pack filePath))
87 , ("name", Encode.name moduleName)
86 , ("name", Encode.name moduleName)
88− , ("errors", Encode.array (map reportToJson reports))
87+ , ("problems", Encode.array (map reportToJson reports))
89 ]
88 ]
90
89
91
90
92reportToJson :: Report.Report -> Encode.Value
91reportToJson :: Report.Report -> Encode.Value
93reportToJson (Report.Report title region _sgstns message) =
92reportToJson (Report.Report title region _sgstns message) =
94− let
95− messageString =
96− P.displayS (P.renderPretty 1 80 message) ""
97− in
98 Encode.object
93 Encode.object
99 [ ("title", Encode.text (Text.pack title))
94 [ ("title", Encode.text (Text.pack title))
100 , ("region", Region.encode region)
95 , ("region", Region.encode region)
101− , ("message", Encode.text (Text.pack messageString))
96+ , ("message", D.encode message)
102 ]
97 ]
compiler/src/Elm/Compiler/Type.hs+24−24
@@ -16,14 +16,14 @@ module Elm.Compiler.Type
16
16
17import qualified Data.Text as Text
17import qualified Data.Text as Text
18import qualified Data.Text.Encoding as Text
18import qualified Data.Text.Encoding as Text
19−import qualified Text.PrettyPrint.ANSI.Leijen as P
20−import Text.PrettyPrint.ANSI.Leijen ((<+>))
21
19
22import qualified AST.Source as Src
20import qualified AST.Source as Src
23import qualified Elm.Name as N
21import qualified Elm.Name as N
24import qualified Parse.Primitives as Parse
22import qualified Parse.Primitives as Parse
25import qualified Parse.Type as Type
23import qualified Parse.Type as Type
26import qualified Reporting.Annotation as A
24import qualified Reporting.Annotation as A
25+import qualified Reporting.Doc as D
26+import Reporting.Doc ((<>), (<+>))
27import qualified Json.Decode as Decode
27import qualified Json.Decode as Decode
28import qualified Json.Encode as Encode
28import qualified Json.Encode as Encode
29import Json.Encode ((==>))
29import Json.Encode ((==>))
@@ -61,7 +61,7 @@ data Union = Union N.Name [N.Name] [(N.Name, [Type])]
61data Context = None | InType | InFunction
61data Context = None | InType | InFunction
62
62
63
63
64−toDoc :: Context -> Type -> P.Doc
64+toDoc :: Context -> Type -> D.Doc
65toDoc context tipe =
65toDoc context tipe =
66 case tipe of
66 case tipe of
67 Lambda _ _ ->
67 Lambda _ _ ->
@@ -69,21 +69,21 @@ toDoc context tipe =
69 map (toDoc InFunction) (collectLambdas tipe)
69 map (toDoc InFunction) (collectLambdas tipe)
70
70
71 lambda =
71 lambda =
72− P.sep [ t, P.sep (map (P.text "->" <+>) ts) ]
72+ D.sep [ t, D.sep (map ("->" <+>) ts) ]
73 in
73 in
74 case context of
74 case context of
75 None -> lambda
75 None -> lambda
76− _ -> P.parens lambda
76+ _ -> "(" <> lambda <> ")"
77
77
78 Var name ->
78 Var name ->
79− P.text (N.toString name)
79+ D.fromName name
80
80
81 Unit ->
81 Unit ->
82 "()"
82 "()"
83
83
84 Tuple a b cs ->
84 Tuple a b cs ->
85− P.sep
85+ D.sep
86− [ P.cat $
86+ [ D.cat $
87 [ "(" <+> toDoc None a
87 [ "(" <+> toDoc None a
88 , "," <+> toDoc None b
88 , "," <+> toDoc None b
89 ]
89 ]
@@ -94,19 +94,19 @@ toDoc context tipe =
94 Type name args ->
94 Type name args ->
95 case args of
95 case args of
96 [] ->
96 [] ->
97− P.text (N.toString name)
97+ D.fromName name
98
98
99 _ ->
99 _ ->
100 let
100 let
101 docName =
101 docName =
102− P.text (N.toString name)
102+ D.fromName name
103
103
104 application =
104 application =
105− P.hang 2 $ P.sep (docName : map (toDoc InType) args)
105+ D.hang 2 $ D.sep (docName : map (toDoc InType) args)
106 in
106 in
107 case context of
107 case context of
108 InType ->
108 InType ->
109− P.parens application
109+ "(" <> application <> ")"
110
110
111 _ ->
111 _ ->
112 application
112 application
@@ -117,23 +117,24 @@ toDoc context tipe =
117 Record fields ext ->
117 Record fields ext ->
118 case ext of
118 case ext of
119 Nothing ->
119 Nothing ->
120− P.sep
120+ D.sep
121− [ P.cat (zipWith (<+>) ("{" : repeat ",") (map entryToDoc fields))
121+ [ D.cat (zipWith (<+>) ("{" : repeat ",") (map entryToDoc fields))
122 , "}"
122 , "}"
123 ]
123 ]
124
124
125 Just x ->
125 Just x ->
126+ D.sep
126− P.hang 4 $
127+ [ D.hang 4 $ D.sep $
127− P.sep
128+ [ "{" <+> D.fromName x
128− [ "{" <+> P.text (N.toString x) <+> "|"
129− , P.sep (P.punctuate "," (map entryToDoc fields))
129+ , D.cat (zipWith (<+>) ("|" : repeat ",") (map entryToDoc fields))
130+ ]
130− , "}"
131+ , "}"
131− ]
132+ ]
132
133
133
134
134−entryToDoc :: (N.Name, Type) -> P.Doc
135+entryToDoc :: (N.Name, Type) -> D.Doc
135entryToDoc (field, fieldType) =
136entryToDoc (field, fieldType) =
136− P.text (N.toString field) <+> ":" <+> toDoc None fieldType
137+ D.fromName field <+> ":" <+> toDoc None fieldType
137
138
138
139
139collectLambdas :: Type -> [Type]
140collectLambdas :: Type -> [Type]
@@ -149,8 +150,7 @@ collectLambdas tipe =
149
150
150encode :: Type -> Encode.Value
151encode :: Type -> Encode.Value
151encode tipe =
152encode tipe =
152− Encode.text $ Text.pack $
153+ Encode.text $ Text.pack $ D.toLine (toDoc None tipe)
153− P.displayS (P.renderPretty 1.0 (maxBound `div` 2) (toDoc None tipe)) ""
154
154
155
155
156decoder :: Decode.Decoder () Type
156decoder :: Decode.Decoder () Type
compiler/src/Elm/Utils.hsdeleted−14
@@ -1,14 +0,0 @@
1−{-# OPTIONS_GHC -Wall #-}
2−module Elm.Utils
3− ( drawCycle
4− , nearbyNames
5− , distance
6− , Entry(..)
7− , parseEntry
8− )
9− where
10−
11−
12−import Parse.Repl (Entry(..), parseEntry)
13−import Reporting.Helpers (drawCycle, nearbyNames, distance)
14−
compiler/src/Generate/JavaScript.hs+4−5
@@ -17,7 +17,6 @@ import qualified Data.Map as Map
17import qualified Data.Set as Set
17import qualified Data.Set as Set
18import qualified Data.Text as Text
18import qualified Data.Text as Text
19import qualified Data.Text.Encoding as Text
19import qualified Data.Text.Encoding as Text
20−import qualified Text.PrettyPrint.ANSI.Leijen as P
21
20
22import qualified AST.Canonical as Can
21import qualified AST.Canonical as Can
23import qualified AST.Optimized as Opt
22import qualified AST.Optimized as Opt
@@ -30,7 +29,7 @@ import qualified Elm.Name as N
30import qualified Generate.JavaScript.Builder as JS
29import qualified Generate.JavaScript.Builder as JS
31import qualified Generate.JavaScript.Expression as Expr
30import qualified Generate.JavaScript.Expression as Expr
32import qualified Generate.JavaScript.Name as Name
31import qualified Generate.JavaScript.Name as Name
33−import qualified Reporting.Helpers as H
32+import qualified Reporting.Doc as D
34
33
35
34
36
35
@@ -98,10 +97,10 @@ print home name annotation =
98 let
97 let
99 value = Name.toBuilder (Name.fromGlobal home name)
98 value = Name.toBuilder (Name.fromGlobal home name)
100 toString = Name.toBuilder (Name.fromKernel N.debug "toString")
99 toString = Name.toBuilder (Name.fromKernel N.debug "toString")
101− tipe = P.displayS (P.renderPretty 1.0 80 (Type.toDoc Type.None (Extract.fromAnnotation annotation))) ""
100+ tipe = Type.toDoc Type.None (Extract.fromAnnotation annotation)
102 in
101 in
103 "var _value = " <> toString <> "(" <> value <> ");\n" <>
102 "var _value = " <> toString <> "(" <> value <> ");\n" <>
104− "var _type = " <> B.stringUtf8 (show tipe) <> ";\n\
103+ "var _type = " <> B.stringUtf8 (show (D.toString tipe)) <> ";\n\
105 \if (_value.length + 3 + _type.length >= 80 || _type.indexOf('\\n') >= 0) {\n\
104 \if (_value.length + 3 + _type.length >= 80 || _type.indexOf('\\n') >= 0) {\n\
106 \ console.log(_value + '\\n : ' + _type.split('\\n').join('\\n '));\n\
105 \ console.log(_value + '\\n : ' + _type.split('\\n').join('\\n '));\n\
107 \} else {\n\
106 \} else {\n\
@@ -244,7 +243,7 @@ generateCycle mode (Opt.Global home _) cycle =
244 "The following top-level definitions are causing infinite recursion:\\n"
243 "The following top-level definitions are causing infinite recursion:\\n"
245 <> drawCycle (map fst cycle)
244 <> drawCycle (map fst cycle)
246 <> "\\n\\nThese errors are very tricky, so read "
245 <> "\\n\\nThese errors are very tricky, so read "
247− <> B.stringUtf8 (H.makeLink "halting-problem")
246+ <> B.stringUtf8 (D.makeLink "halting-problem")
248 <> " to learn how to fix it!"
247 <> " to learn how to fix it!"
249
248
250
249
compiler/src/Json/Decode.hs+2−2
@@ -33,8 +33,8 @@ import Parse.Primitives.Internals (Parser(..), State(..), noError)
33import qualified Parse.Primitives.Keyword as Keyword
33import qualified Parse.Primitives.Keyword as Keyword
34import qualified Parse.Primitives.Number as Number
34import qualified Parse.Primitives.Number as Number
35import qualified Parse.Primitives.Symbol as Symbol
35import qualified Parse.Primitives.Symbol as Symbol
36+import qualified Reporting.Doc as D
36import qualified Reporting.Error.Syntax as E
37import qualified Reporting.Error.Syntax as E
37−import qualified Reporting.Helpers as H
38import qualified Reporting.Region as R
38import qualified Reporting.Region as R
39import qualified Reporting.Render.Code as Code
39import qualified Reporting.Render.Code as Code
40
40
@@ -43,7 +43,7 @@ import qualified Reporting.Render.Code as Code
43-- PARSE
43-- PARSE
44
44
45
45
46−parse :: String -> (e -> [H.Doc]) -> Json.Decoder e a -> B.ByteString -> Either H.Doc a
46+parse :: String -> (e -> [D.Doc]) -> Json.Decoder e a -> B.ByteString -> Either D.Doc a
47parse rootName userErrorToDocs (Json.Decoder run) bytestring =
47parse rootName userErrorToDocs (Json.Decoder run) bytestring =
48 let
48 let
49 source =
49 source =
compiler/src/Json/Decode/Error.hs+27−27
@@ -16,8 +16,8 @@ import qualified Text.PrettyPrint.ANSI.Leijen as P
16
16
17import qualified Json.Decode.Internals as Json
17import qualified Json.Decode.Internals as Json
18import qualified Json.Encode as E
18import qualified Json.Encode as E
19+import qualified Reporting.Doc as D
19import qualified Reporting.Error.Syntax as Syntax
20import qualified Reporting.Error.Syntax as Syntax
20−import qualified Reporting.Helpers as H
21import qualified Reporting.Render.Code as Code
21import qualified Reporting.Render.Code as Code
22import qualified Reporting.Report as Report
22import qualified Reporting.Report as Report
23
23
@@ -35,7 +35,7 @@ data Error e
35-- TO DOC
35-- TO DOC
36
36
37
37
38−toDoc :: String -> Code.Source -> (e -> [H.Doc]) -> Error e -> H.Doc
38+toDoc :: String -> Code.Source -> (e -> [D.Doc]) -> Error e -> D.Doc
39toDoc rootName source userErrorToDocs err =
39toDoc rootName source userErrorToDocs err =
40 case err of
40 case err of
41 BadJson syntaxError ->
41 BadJson syntaxError ->
@@ -46,7 +46,7 @@ toDoc rootName source userErrorToDocs err =
46 BadContent jsonError ->
46 BadContent jsonError ->
47 case flatten jsonError of
47 case flatten jsonError of
48 [] ->
48 [] ->
49− H.reflow
49+ D.reflow
50 "I am not sure what is wrong with this JSON. Please create an <http://sscce.org>\
50 "I am not sure what is wrong with this JSON. Please create an <http://sscce.org>\
51 \ and share it at <https://github.com/elm-lang/elm-compiler/issues> so I can\
51 \ and share it at <https://github.com/elm-lang/elm-compiler/issues> so I can\
52 \ provide a helpful hint here!"
52 \ provide a helpful hint here!"
@@ -59,8 +59,8 @@ toDoc rootName source userErrorToDocs err =
59 toNumberedDoc index flatErr =
59 toNumberedDoc index flatErr =
60 P.dullcyan ("(" <> P.int index <> ")") <+> flatErrorToDoc rootName [] userErrorToDocs flatErr
60 P.dullcyan ("(" <> P.int index <> ")") <+> flatErrorToDoc rootName [] userErrorToDocs flatErr
61 in
61 in
62− H.stack $
62+ D.stack $
63− [ H.reflow $
63+ [ D.reflow $
64 "I have " ++ show (length flatErrors) ++ " theories on what is going wrong:"
64 "I have " ++ show (length flatErrors) ++ " theories on what is going wrong:"
65 ]
65 ]
66 ++ zipWith toNumberedDoc [1..] flatErrors
66 ++ zipWith toNumberedDoc [1..] flatErrors
@@ -70,7 +70,7 @@ toDoc rootName source userErrorToDocs err =
70-- FLAT ERROR TO DOC
70-- FLAT ERROR TO DOC
71
71
72
72
73−flatErrorToDoc :: String -> [H.Doc] -> (e -> [H.Doc]) -> FlatError e -> H.Doc
73+flatErrorToDoc :: String -> [D.Doc] -> (e -> [D.Doc]) -> FlatError e -> D.Doc
74flatErrorToDoc rootName starter userErrorToDocs (FlatError accesses json theory theories) =
74flatErrorToDoc rootName starter userErrorToDocs (FlatError accesses json theory theories) =
75 case theories of
75 case theories of
76 [] ->
76 [] ->
@@ -85,12 +85,12 @@ flatErrorToDoc rootName starter userErrorToDocs (FlatError accesses json theory
85 in
85 in
86 case accesses of
86 case accesses of
87 [] ->
87 [] ->
88− H.fillSep (starter ++ explanation)
88+ D.fillSep (starter ++ explanation)
89
89
90 _ ->
90 _ ->
91− H.stack
91+ D.stack
92− [ H.fillSep $ starter ++ ["The"] ++ actualThing json ++ ["at",accessToDoc rootName accesses,"is","causing","issues."]
92+ [ D.fillSep $ starter ++ ["The"] ++ actualThing json ++ ["at",accessToDoc rootName accesses,"is","causing","issues."]
93− , H.fillSep explanation
93+ , D.fillSep explanation
94 ]
94 ]
95
95
96 _:_ ->
96 _:_ ->
@@ -107,31 +107,31 @@ flatErrorToDoc rootName starter userErrorToDocs (FlatError accesses json theory
107 ++ actualThing json
107 ++ actualThing json
108 ++ ["at",accessToDoc rootName accesses,"because:"]
108 ++ ["at",accessToDoc rootName accesses,"because:"]
109 in
109 in
110− H.stack
110+ D.stack
111− [ H.fillSep (starter ++ introduction)
111+ [ D.fillSep (starter ++ introduction)
112− , H.stack (toBullet [] userErrorToDocs theory : map (toBullet ["OR"] userErrorToDocs) theories)
112+ , D.stack (toBullet [] userErrorToDocs theory : map (toBullet ["OR"] userErrorToDocs) theories)
113− , H.reflow "I accept any of these things."
113+ , D.reflow "I accept any of these things."
114 ]
114 ]
115
115
116
116
117−accessToDoc :: String -> [String] -> H.Doc
117+accessToDoc :: String -> [String] -> D.Doc
118accessToDoc rootName accesses =
118accessToDoc rootName accesses =
119 P.dullyellow (P.text (rootName ++ concat accesses))
119 P.dullyellow (P.text (rootName ++ concat accesses))
120
120
121
121
122−actualThing :: E.Value -> [H.Doc]
122+actualThing :: E.Value -> [D.Doc]
123actualThing json =
123actualThing json =
124 case json of
124 case json of
125− E.Array _ -> [H.red "array"]
125+ E.Array _ -> [D.red "array"]
126− E.Object _ -> [H.red "object"]
126+ E.Object _ -> [D.red "object"]
127− E.String _ -> [H.red "string"]
127+ E.String _ -> [D.red "string"]
128− E.Boolean b -> [H.red (if b then "true" else "false"),"value"]
128+ E.Boolean b -> [D.red (if b then "true" else "false"),"value"]
129− E.Integer n -> ["number",H.red (H.text (show n))]
129+ E.Integer n -> ["number",D.red (D.fromString (show n))]
130− E.Number _ -> [H.red "number"]
130+ E.Number _ -> [D.red "number"]
131− E.Null -> [H.red "null","value"]
131+ E.Null -> [D.red "null","value"]
132
132
133
133
134−anExpectedThing :: Json.Type -> [H.Doc]
134+anExpectedThing :: Json.Type -> [D.Doc]
135anExpectedThing tipe =
135anExpectedThing tipe =
136 case tipe of
136 case tipe of
137 Json.TObject -> ["an", P.green "OBJECT" <> "."]
137 Json.TObject -> ["an", P.green "OBJECT" <> "."]
@@ -141,15 +141,15 @@ anExpectedThing tipe =
141 Json.TInt -> ["an", P.green "INT" <> "."]
141 Json.TInt -> ["an", P.green "INT" <> "."]
142 Json.TObjectWith field -> ["an",P.green "OBJECT","with","a",P.green ("\"" <> P.text (Text.unpack field) <> "\""),"field."]
142 Json.TObjectWith field -> ["an",P.green "OBJECT","with","a",P.green ("\"" <> P.text (Text.unpack field) <> "\""),"field."]
143 Json.TArrayWith i len ->
143 Json.TArrayWith i len ->
144− ["a",H.green "longer",P.green "ARRAY" <> "."
144+ ["a",D.green "longer",P.green "ARRAY" <> "."
145 ,"I","need","index",P.text (show i) <> ",","but","this","array"
145 ,"I","need","index",P.text (show i) <> ",","but","this","array"
146 ,"only","has",P.text (show len),"elements."
146 ,"only","has",P.text (show len),"elements."
147 ]
147 ]
148
148
149
149
150−toBullet :: [H.Doc] -> (e -> [H.Doc]) -> Theory e -> H.Doc
150+toBullet :: [D.Doc] -> (e -> [D.Doc]) -> Theory e -> D.Doc
151toBullet intro userErrorToDocs theory =
151toBullet intro userErrorToDocs theory =
152− H.indent 4 $ H.fillSep $ (++) intro $
152+ D.indent 4 $ D.fillSep $ (++) intro $
153 case theory of
153 case theory of
154 Failure userError ->
154 Failure userError ->
155 userErrorToDocs userError
155 userErrorToDocs userError
compiler/src/Reporting/Error/Canonicalize.hs+205−204
@@ -23,12 +23,13 @@ import qualified AST.Module.Name as ModuleName
23import qualified Data.Index as Index
23import qualified Data.Index as Index
24import qualified Elm.Name as N
24import qualified Elm.Name as N
25import qualified Reporting.Annotation as A
25import qualified Reporting.Annotation as A
26+import qualified Reporting.Doc as D
27+import Reporting.Doc (Doc, (<+>), (<>))
26import qualified Reporting.Region as R
28import qualified Reporting.Region as R
27import qualified Reporting.Render.Code as Code
29import qualified Reporting.Render.Code as Code
28import qualified Reporting.Render.Type as RT
30import qualified Reporting.Render.Type as RT
29import qualified Reporting.Report as Report
31import qualified Reporting.Report as Report
30−import qualified Reporting.Helpers as H
32+import qualified Reporting.Suggest as Suggest
31−import Reporting.Helpers ( Doc, (<+>), (<>) )
32
33
33
34
34
35
@@ -126,16 +127,16 @@ toKindInfo :: VarKind -> N.Name -> ( Doc, Doc, Doc )
126toKindInfo kind name =
127toKindInfo kind name =
127 case kind of
128 case kind of
128 BadOp ->
129 BadOp ->
129− ( "an", "operator", "(" <> H.nameToDoc name <> ")" )
130+ ( "an", "operator", "(" <> D.fromName name <> ")" )
130
131
131 BadVar ->
132 BadVar ->
132− ( "a", "value", "`" <> H.nameToDoc name <> "`" )
133+ ( "a", "value", "`" <> D.fromName name <> "`" )
133
134
134 BadPattern ->
135 BadPattern ->
135− ( "a", "pattern", "`" <> H.nameToDoc name <> "`" )
136+ ( "a", "pattern", "`" <> D.fromName name <> "`" )
136
137
137 BadType ->
138 BadType ->
138− ( "a", "type", "`" <> H.nameToDoc name <> "`" )
139+ ( "a", "type", "`" <> D.fromName name <> "`" )
139
140
140
141
141
142
@@ -153,12 +154,12 @@ toReport source err =
153 Report.Report "BAD TYPE ANNOTATION" region [] $
154 Report.Report "BAD TYPE ANNOTATION" region [] $
154 Report.toCodeSnippet source region Nothing
155 Report.toCodeSnippet source region Nothing
155 (
156 (
156− H.reflow $
157+ D.reflow $
157 "The type annotation for `" <> N.toString name <> "` says it can accept "
158 "The type annotation for `" <> N.toString name <> "` says it can accept "
158− <> H.args numTypeArgs <> ", but the definition says it has "
159+ <> D.args numTypeArgs <> ", but the definition says it has "
159− <> H.args numDefArgs <> ":"
160+ <> D.args numDefArgs <> ":"
160 ,
161 ,
161− H.reflow $
162+ D.reflow $
162 "Is the type annotation missing something? Should some argument"
163 "Is the type annotation missing something? Should some argument"
163 <> (if leftovers == 1 then "" else "s")
164 <> (if leftovers == 1 then "" else "s")
164 <> " be deleted? Maybe some parentheses are missing?"
165 <> " be deleted? Maybe some parentheses are missing?"
@@ -187,20 +188,20 @@ toReport source err =
187 Report.Report "TOO FEW ARGS" region [] $
188 Report.Report "TOO FEW ARGS" region [] $
188 Report.toCodeSnippet source region Nothing
189 Report.toCodeSnippet source region Nothing
189 (
190 (
190− H.reflow $
191+ D.reflow $
191− "The `" <> N.toString name <> "` " <> thing <> " was given " <> H.args actual <> ":"
192+ "The `" <> N.toString name <> "` " <> thing <> " was given " <> D.args actual <> ":"
192 ,
193 ,
193− H.reflow $
194+ D.reflow $
194− "But it needs " <> H.args expected <> ". What is missing? Are some parentheses misplaced?"
195+ "But it needs " <> D.args expected <> ". What is missing? Are some parentheses misplaced?"
195 )
196 )
196
197
197 else
198 else
198 Report.Report "TOO MANY ARGS" region [] $
199 Report.Report "TOO MANY ARGS" region [] $
199 Report.toCodeSnippet source region Nothing
200 Report.toCodeSnippet source region Nothing
200 (
201 (
201− H.reflow $
202+ D.reflow $
202 "The `" <> N.toString name <> "` " <> thing <> " needs "
203 "The `" <> N.toString name <> "` " <> thing <> " needs "
203− <> H.args expected <> ", but I see " <> show actual <> " instead:"
204+ <> D.args expected <> ", but I see " <> show actual <> " instead:"
204 ,
205 ,
205 if actual - expected == 1 then
206 if actual - expected == 1 then
206 "Which is the extra one? Maybe some parentheses are missing?"
207 "Which is the extra one? Maybe some parentheses are missing?"
@@ -212,10 +213,10 @@ toReport source err =
212 Report.Report "INFIX PROBLEM" region [] $
213 Report.Report "INFIX PROBLEM" region [] $
213 Report.toCodeSnippet source region Nothing
214 Report.toCodeSnippet source region Nothing
214 (
215 (
215− H.reflow $
216+ D.reflow $
216 "You cannot mix (" <> N.toString op1 <> ") and (" <> N.toString op2 <> ") without parentheses."
217 "You cannot mix (" <> N.toString op1 <> ") and (" <> N.toString op2 <> ") without parentheses."
217 ,
218 ,
218− H.reflow
219+ D.reflow
219 "I do not know how to group these expressions. Add parentheses for me!"
220 "I do not know how to group these expressions. Add parentheses for me!"
220 )
221 )
221
222
@@ -269,10 +270,10 @@ toReport source err =
269 Report.Report "EFFECT PROBLEM" region [] $
270 Report.Report "EFFECT PROBLEM" region [] $
270 Report.toCodeSnippet source region Nothing
271 Report.toCodeSnippet source region Nothing
271 (
272 (
272− H.reflow $
273+ D.reflow $
273 "You have declared that `" ++ N.toString name ++ "` is an effect type:"
274 "You have declared that `" ++ N.toString name ++ "` is an effect type:"
274 ,
275 ,
275− H.reflow $
276+ D.reflow $
276 "But I cannot find a union type named `" ++ N.toString name ++ "` in this file!"
277 "But I cannot find a union type named `" ++ N.toString name ++ "` in this file!"
277 )
278 )
278
279
@@ -280,10 +281,10 @@ toReport source err =
280 Report.Report "EFFECT PROBLEM" region [] $
281 Report.Report "EFFECT PROBLEM" region [] $
281 Report.toCodeSnippet source region Nothing
282 Report.toCodeSnippet source region Nothing
282 (
283 (
283− H.reflow $
284+ D.reflow $
284 "This kind of effect module must define a `" ++ N.toString name ++ "` function."
285 "This kind of effect module must define a `" ++ N.toString name ++ "` function."
285 ,
286 ,
286− H.reflow $
287+ D.reflow $
287 "But I cannot find `" ++ N.toString name ++ "` in this file!"
288 "But I cannot find `" ++ N.toString name ++ "` in this file!"
288 )
289 )
289
290
@@ -296,12 +297,12 @@ toReport source err =
296 Report.Report "REDUNDANT EXPORT" r2 [] $
297 Report.Report "REDUNDANT EXPORT" r2 [] $
297 Report.toCodePair source r1 r2
298 Report.toCodePair source r1 r2
298 (
299 (
299− H.reflow messageThatEndsWithPunctuation
300+ D.reflow messageThatEndsWithPunctuation
300 ,
301 ,
301 "Remove one of them and you should be all set!"
302 "Remove one of them and you should be all set!"
302 )
303 )
303 (
304 (
304− H.reflow (messageThatEndsWithPunctuation <> " Once here:")
305+ D.reflow (messageThatEndsWithPunctuation <> " Once here:")
305 ,
306 ,
306 "And again right here:"
307 "And again right here:"
307 ,
308 ,
@@ -312,27 +313,27 @@ toReport source err =
312 let
313 let
313 suggestions =
314 suggestions =
314 map N.toString $ take 4 $
315 map N.toString $ take 4 $
315− H.nearbyNames N.toString rawName possibleNames
316+ Suggest.nearbyNames N.toString rawName possibleNames
316 in
317 in
317 Report.Report "UNKNOWN EXPORT" region suggestions $
318 Report.Report "UNKNOWN EXPORT" region suggestions $
318 let (a, thing, name) = toKindInfo kind rawName in
319 let (a, thing, name) = toKindInfo kind rawName in
319− H.stack
320+ D.stack
320− [ H.fillSep
321+ [ D.fillSep
321 ["You","are","trying","to","expose",a,thing,"named"
322 ["You","are","trying","to","expose",a,thing,"named"
322 ,name,"but","I","cannot","find","its","definition."
323 ,name,"but","I","cannot","find","its","definition."
323 ]
324 ]
324− , case map H.text suggestions of
325+ , case map D.fromString suggestions of
325 [] ->
326 [] ->
326− H.reflow $
327+ D.reflow $
327 "I do not see any super similar names in this file. Is the definition missing?"
328 "I do not see any super similar names in this file. Is the definition missing?"
328
329
329 [alt] ->
330 [alt] ->
330− H.fillSep ["Maybe","you","want",H.dullyellow alt,"instead?"]
331+ D.fillSep ["Maybe","you","want",D.dullyellow alt,"instead?"]
331
332
332 alts ->
333 alts ->
333− H.stack
334+ D.stack
334 [ "These names seem close though:"
335 [ "These names seem close though:"
335− , H.indent 4 $ H.vcat $ map H.dullyellow alts
336+ , D.indent 4 $ D.vcat $ map D.dullyellow alts
336 ]
337 ]
337 ]
338 ]
338
339
@@ -340,11 +341,11 @@ toReport source err =
340 Report.Report "BAD EXPORT" region [] $
341 Report.Report "BAD EXPORT" region [] $
341 Report.toCodeSnippet source region Nothing
342 Report.toCodeSnippet source region Nothing
342 (
343 (
343− H.reflow $
344+ D.reflow $
344 "The (..) syntax is for exposing union type constructors. It cannot be used with a type alias like `"
345 "The (..) syntax is for exposing union type constructors. It cannot be used with a type alias like `"
345 ++ N.toString name ++ "` though."
346 ++ N.toString name ++ "` though."
346 ,
347 ,
347− H.reflow $
348+ D.reflow $
348 "Remove the (..) and you should be fine!"
349 "Remove the (..) and you should be fine!"
349 )
350 )
350
351
@@ -352,15 +353,15 @@ toReport source err =
352 Report.Report "BAD IMPORT" region [] $
353 Report.Report "BAD IMPORT" region [] $
353 Report.toCodeSnippet source region Nothing
354 Report.toCodeSnippet source region Nothing
354 (
355 (
355− H.reflow $
356+ D.reflow $
356 "You are trying to import the `" <> N.toString ctor
357 "You are trying to import the `" <> N.toString ctor
357 <> "` type constructor by name:"
358 <> "` type constructor by name:"
358 ,
359 ,
359− H.fillSep
360+ D.fillSep
360− ["Try","importing",H.green (H.nameToDoc tipe <> "(..)"),"instead."
361+ ["Try","importing",D.green (D.fromName tipe <> "(..)"),"instead."
361− ,"The","dots","mean","“expose","the",H.nameToDoc tipe,"type","and"
362+ ,"The","dots","mean","“expose","the",D.fromName tipe,"type","and"
362 ,"all","its","constructors”","so","it","gives","you","access","to"
363 ,"all","its","constructors”","so","it","gives","you","access","to"
363− , H.nameToDoc ctor <> "."
364+ , D.fromName ctor <> "."
364 ]
365 ]
365 )
366 )
366
367
@@ -372,7 +373,7 @@ toReport source err =
372 Report.Report "UNKNOWN IMPORT" region [] $
373 Report.Report "UNKNOWN IMPORT" region [] $
373 Report.toCodeSnippet source region Nothing
374 Report.toCodeSnippet source region Nothing
374 (
375 (
375− H.reflow $
376+ D.reflow $
376 "I could not find a `" <> N.toString name <> "` module to import!"
377 "I could not find a `" <> N.toString name <> "` module to import!"
377 ,
378 ,
378 mempty
379 mempty
@@ -382,12 +383,12 @@ toReport source err =
382 Report.Report "BAD IMPORT" region [] $
383 Report.Report "BAD IMPORT" region [] $
383 Report.toCodeSnippet source region Nothing
384 Report.toCodeSnippet source region Nothing
384 (
385 (
385− H.reflow $
386+ D.reflow $
386 "The `" <> N.toString name <> "` type alias cannot be followed by (..) like this:"
387 "The `" <> N.toString name <> "` type alias cannot be followed by (..) like this:"
387 ,
388 ,
388− H.stack
389+ D.stack
389 [ "Remove the (..) and it should work."
390 [ "Remove the (..) and it should work."
390− , H.link "Hint"
391+ , D.link "Hint"
391 "The distinction between `type` and `type alias` is important here. Read"
392 "The distinction between `type` and `type alias` is important here. Read"
392 "types-vs-type-aliases"
393 "types-vs-type-aliases"
393 "to learn more."
394 "to learn more."
@@ -398,27 +399,27 @@ toReport source err =
398 let
399 let
399 suggestions =
400 suggestions =
400 map N.toString $ take 4 $
401 map N.toString $ take 4 $
401− H.nearbyNames N.toString home possibleNames
402+ Suggest.nearbyNames N.toString home possibleNames
402 in
403 in
403 Report.Report "BAD IMPORT" region suggestions $
404 Report.Report "BAD IMPORT" region suggestions $
404 Report.toCodeSnippet source region Nothing
405 Report.toCodeSnippet source region Nothing
405 (
406 (
406− H.reflow $
407+ D.reflow $
407 "The `" <> N.toString home
408 "The `" <> N.toString home
408 <> "` module does not expose `"
409 <> "` module does not expose `"
409 <> N.toString value <> "`:"
410 <> N.toString value <> "`:"
410 ,
411 ,
411− case map H.text suggestions of
412+ case map D.fromString suggestions of
412 [] ->
413 [] ->
413 "I cannot find any super similar exposed names. Maybe it is private?"
414 "I cannot find any super similar exposed names. Maybe it is private?"
414
415
415 [alt] ->
416 [alt] ->
416− H.fillSep ["Maybe","you","want",H.dullyellow alt,"instead?"]
417+ D.fillSep ["Maybe","you","want",D.dullyellow alt,"instead?"]
417
418
418 alts ->
419 alts ->
419− H.stack
420+ D.stack
420 [ "These names seem close though:"
421 [ "These names seem close though:"
421− , H.indent 4 $ H.vcat $ map H.dullyellow alts
422+ , D.indent 4 $ D.vcat $ map D.dullyellow alts
422 ]
423 ]
423 )
424 )
424
425
@@ -445,12 +446,12 @@ toReport source err =
445 Report.Report "UNKNOWN OPERATOR" region ["/="] $
446 Report.Report "UNKNOWN OPERATOR" region ["/="] $
446 Report.toCodeSnippet source region Nothing
447 Report.toCodeSnippet source region Nothing
447 (
448 (
448− H.reflow $
449+ D.reflow $
449 "Elm uses a different name for the “not equal” operator:"
450 "Elm uses a different name for the “not equal” operator:"
450 ,
451 ,
451− H.stack
452+ D.stack
452− [ H.reflow "Switch to (/=) instead."
453+ [ D.reflow "Switch to (/=) instead."
453− , H.toSimpleNote $
454+ , D.toSimpleNote $
454 "Our (/=) operator is supposed to look like a real “not equal” sign (≠). I hope that history will remember ("
455 "Our (/=) operator is supposed to look like a real “not equal” sign (≠). I hope that history will remember ("
455 ++ N.toString op ++ ") as a werid and temporary choice."
456 ++ N.toString op ++ ") as a werid and temporary choice."
456 ]
457 ]
@@ -460,10 +461,10 @@ toReport source err =
460 Report.Report "UNKNOWN OPERATOR" region ["^","*"] $
461 Report.Report "UNKNOWN OPERATOR" region ["^","*"] $
461 Report.toCodeSnippet source region Nothing
462 Report.toCodeSnippet source region Nothing
462 (
463 (
463− H.reflow $
464+ D.reflow $
464 "I do not recognize the (**) operator:"
465 "I do not recognize the (**) operator:"
465 ,
466 ,
466− H.reflow $
467+ D.reflow $
467 "Switch to (^) for exponentiation. Or switch to (*) for multiplication."
468 "Switch to (^) for exponentiation. Or switch to (*) for multiplication."
468 )
469 )
469
470
@@ -471,17 +472,17 @@ toReport source err =
471 Report.Report "UNKNOWN OPERATOR" region [] $
472 Report.Report "UNKNOWN OPERATOR" region [] $
472 Report.toCodeSnippet source region Nothing
473 Report.toCodeSnippet source region Nothing
473 (
474 (
474− H.reflow $
475+ D.reflow $
475 "Elm does not use (%) as the remainder operator:"
476 "Elm does not use (%) as the remainder operator:"
476 ,
477 ,
477− H.stack
478+ D.stack
478− [ H.reflow $
479+ [ D.reflow $
479 "If you want the behavior of (%) like in JavaScript, switch to:\
480 "If you want the behavior of (%) like in JavaScript, switch to:\
480 \ <https://package.elm-lang.org/packages/elm-lang/core/latest/Basics#remainderBy>"
481 \ <https://package.elm-lang.org/packages/elm-lang/core/latest/Basics#remainderBy>"
481− , H.reflow $
482+ , D.reflow $
482 "If you want modular arithmatic like in math, switch to:\
483 "If you want modular arithmatic like in math, switch to:\
483 \ <https://package.elm-lang.org/packages/elm-lang/core/latest/Basics#modBy>"
484 \ <https://package.elm-lang.org/packages/elm-lang/core/latest/Basics#modBy>"
484− , H.reflow $
485+ , D.reflow $
485 "The difference is how things work when negative numbers are involved."
486 "The difference is how things work when negative numbers are involved."
486 ]
487 ]
487 )
488 )
@@ -490,37 +491,37 @@ toReport source err =
490 let
491 let
491 suggestions =
492 suggestions =
492 map N.toString $ take 2 $
493 map N.toString $ take 2 $
493− H.nearbyNames N.toString op (Set.toList locals)
494+ Suggest.nearbyNames N.toString op (Set.toList locals)
494
495
495 format altOp =
496 format altOp =
496− H.green $ "(" <> altOp <> ")"
497+ D.green $ "(" <> altOp <> ")"
497 in
498 in
498 Report.Report "UNKNOWN OPERATOR" region suggestions $
499 Report.Report "UNKNOWN OPERATOR" region suggestions $
499 Report.toCodeSnippet source region Nothing
500 Report.toCodeSnippet source region Nothing
500 (
501 (
501− H.reflow $
502+ D.reflow $
502 "I do not recognize the (" ++ N.toString op ++ ") operator."
503 "I do not recognize the (" ++ N.toString op ++ ") operator."
503 ,
504 ,
504− H.fillSep $
505+ D.fillSep $
505 ["Is","there","an","`import`","and","`exposing`","entry","for","it?"]
506 ["Is","there","an","`import`","and","`exposing`","entry","for","it?"]
506 ++
507 ++
507− case map H.text suggestions of
508+ case map D.fromString suggestions of
508 [] ->
509 [] ->
509 []
510 []
510
511
511 alts ->
512 alts ->
512− ["Maybe","you","want"] ++ H.commaSep "or" format alts ++ ["instead?"]
513+ ["Maybe","you","want"] ++ D.commaSep "or" format alts ++ ["instead?"]
513 )
514 )
514
515
515 PatternHasRecordCtor region name ->
516 PatternHasRecordCtor region name ->
516 Report.Report "BAD PATTERN" region [] $
517 Report.Report "BAD PATTERN" region [] $
517 Report.toCodeSnippet source region Nothing
518 Report.toCodeSnippet source region Nothing
518 (
519 (
519− H.reflow $
520+ D.reflow $
520 "You can construct records by using `" <> N.toString name
521 "You can construct records by using `" <> N.toString name
521 <> "` as a function, but it is not available in pattern matching like this:"
522 <> "` as a function, but it is not available in pattern matching like this:"
522 ,
523 ,
523− H.reflow $
524+ D.reflow $
524 "I recommend matching matching the record as a variable and unpacking it later."
525 "I recommend matching matching the record as a variable and unpacking it later."
525 )
526 )
526
527
@@ -530,12 +531,12 @@ toReport source err =
530 Report.Report "PORT ERROR" region [] $
531 Report.Report "PORT ERROR" region [] $
531 Report.toCodeSnippet source region Nothing
532 Report.toCodeSnippet source region Nothing
532 (
533 (
533− H.reflow $
534+ D.reflow $
534 "The `" <> N.toString portName <> "` port is trying to transmit " <> aBadKindOfThing <> ":"
535 "The `" <> N.toString portName <> "` port is trying to transmit " <> aBadKindOfThing <> ":"
535 ,
536 ,
536− H.stack
537+ D.stack
537 [ elaboration
538 [ elaboration
538− , H.link "Hint"
539+ , D.link "Hint"
539 "Ports are not a traditional FFI, so if you have tons of annoying ports, definitely read"
540 "Ports are not a traditional FFI, so if you have tons of annoying ports, definitely read"
540 "ports"
541 "ports"
541 "to learn how they are meant to work. They require a different mindset!"
542 "to learn how they are meant to work. They require a different mindset!"
@@ -548,7 +549,7 @@ toReport source err =
548 (
549 (
549 "an extended record"
550 "an extended record"
550 ,
551 ,
551− H.reflow $
552+ D.reflow $
552 "But the exact shape of the record must be known at compile time. No type variables!"
553 "But the exact shape of the record must be known at compile time. No type variables!"
553 )
554 )
554
555
@@ -556,7 +557,7 @@ toReport source err =
556 (
557 (
557 "a function"
558 "a function"
558 ,
559 ,
559− H.reflow $
560+ D.reflow $
560 "But functions cannot be sent in and out ports. If we allowed functions in from JS\
561 "But functions cannot be sent in and out ports. If we allowed functions in from JS\
561 \ they may perform some side-effects. If we let functions out, they could produce\
562 \ they may perform some side-effects. If we let functions out, they could produce\
562 \ incorrect results because Elm optimizations assume there are no side-effects."
563 \ incorrect results because Elm optimizations assume there are no side-effects."
@@ -567,7 +568,7 @@ toReport source err =
567 (
568 (
568 "an unspecified type"
569 "an unspecified type"
569 ,
570 ,
570− H.reflow $
571+ D.reflow $
571 "But type variables like `" <> N.toString name <> "` cannot flow through ports.\
572 "But type variables like `" <> N.toString name <> "` cannot flow through ports.\
572 \ I need to know exactly what type of data I am getting, so I can guarantee that\
573 \ I need to know exactly what type of data I am getting, so I can guarantee that\
573 \ unexpected data cannot sneak in and crash the Elm program."
574 \ unexpected data cannot sneak in and crash the Elm program."
@@ -577,13 +578,13 @@ toReport source err =
577 (
578 (
578 "a `" <> N.toString name <> "` value"
579 "a `" <> N.toString name <> "` value"
579 ,
580 ,
580− H.stack
581+ D.stack
581− [ H.reflow $ "I cannot handle that. The types that CAN flow in and out of Elm include:"
582+ [ D.reflow $ "I cannot handle that. The types that CAN flow in and out of Elm include:"
582− , H.indent 4 $
583+ , D.indent 4 $
583− H.reflow $
584+ D.reflow $
584 "Ints, Floats, Bools, Strings, Maybes, Lists, Arrays,\
585 "Ints, Floats, Bools, Strings, Maybes, Lists, Arrays,\
585 \ tuples, records, and JSON values."
586 \ tuples, records, and JSON values."
586− , H.reflow $
587+ , D.reflow $
587 "Since JSON values can flow through, you can use JSON encoders and decoders\
588 "Since JSON values can flow through, you can use JSON encoders and decoders\
588 \ to allow other types through as well. More advanced users often just do\
589 \ to allow other types through as well. More advanced users often just do\
589 \ everything with encoders and decoders for more control and better errors."
590 \ everything with encoders and decoders for more control and better errors."
@@ -596,11 +597,11 @@ toReport source err =
596 Report.Report "BAD PORT" region [] $
597 Report.Report "BAD PORT" region [] $
597 Report.toCodeSnippet source region Nothing $
598 Report.toCodeSnippet source region Nothing $
598 (
599 (
599− H.reflow before
600+ D.reflow before
600 ,
601 ,
601− H.stack
602+ D.stack
602 [ after
603 [ after
603− , H.link "Hint" "Read" "ports"
604+ , D.link "Hint" "Read" "ports"
604 "for more advice. For example, do not end up with one port per JS function!"
605 "for more advice. For example, do not end up with one port per JS function!"
605 ]
606 ]
606 )
607 )
@@ -611,7 +612,7 @@ toReport source err =
611 (
612 (
612 "The `" <> N.toString name <> "` port cannot be just a command."
613 "The `" <> N.toString name <> "` port cannot be just a command."
613 ,
614 ,
614− H.reflow $
615+ D.reflow $
615 "It can be (() -> Cmd msg) if you just need to trigger a JavaScript\
616 "It can be (() -> Cmd msg) if you just need to trigger a JavaScript\
616 \ function, but there is often a better way to set things up."
617 \ function, but there is often a better way to set things up."
617 )
618 )
@@ -626,7 +627,7 @@ toReport source err =
626 | n == 3 = "these " ++ show n ++ " items into a tuple or record"
627 | n == 3 = "these " ++ show n ++ " items into a tuple or record"
627 | True = "these " ++ show n ++ " items into a record"
628 | True = "these " ++ show n ++ " items into a record"
628 in
629 in
629− H.reflow $
630+ D.reflow $
630 "You can put " ++ theseItemsInSomething ++ " to send them out though."
631 "You can put " ++ theseItemsInSomething ++ " to send them out though."
631 )
632 )
632
633
@@ -634,7 +635,7 @@ toReport source err =
634 (
635 (
635 "The `" <> N.toString name <> "` port cannot send any messages to the `update` function."
636 "The `" <> N.toString name <> "` port cannot send any messages to the `update` function."
636 ,
637 ,
637− H.reflow $
638+ D.reflow $
638 "It must produce a (Cmd msg) type. Notice the lower case `msg` type\
639 "It must produce a (Cmd msg) type. Notice the lower case `msg` type\
639 \ variable. The command will trigger some JS code, but it will not send\
640 \ variable. The command will trigger some JS code, but it will not send\
640 \ anything particular back to Elm."
641 \ anything particular back to Elm."
@@ -643,12 +644,12 @@ toReport source err =
643 SubBad ->
644 SubBad ->
644 ( "There is something off about this `" <> N.toString name <> "` port declaration."
645 ( "There is something off about this `" <> N.toString name <> "` port declaration."
645 ,
646 ,
646− H.stack
647+ D.stack
647− [ H.reflow $
648+ [ D.reflow $
648 "To receive messages from JavaScript, you need to define a port like this:"
649 "To receive messages from JavaScript, you need to define a port like this:"
649− , H.indent 4 $ H.dullyellow $ H.text $
650+ , D.indent 4 $ D.dullyellow $ D.fromString $
650 "port " <> N.toString name <> " : (Int -> msg) -> Sub msg"
651 "port " <> N.toString name <> " : (Int -> msg) -> Sub msg"
651− , H.reflow $
652+ , D.reflow $
652 "Now every time JS sends an `Int` to this port, it is converted to a `msg`.\
653 "Now every time JS sends an `Int` to this port, it is converted to a `msg`.\
653 \ And if you subscribe, those `msg` values will be piped into your `update`\
654 \ And if you subscribe, those `msg` values will be piped into your `update`\
654 \ function. The only thing you can customize here is the `Int` type."
655 \ function. The only thing you can customize here is the `Int` type."
@@ -659,7 +660,7 @@ toReport source err =
659 (
660 (
660 "I am confused about the `" <> N.toString name <> "` port declaration."
661 "I am confused about the `" <> N.toString name <> "` port declaration."
661 ,
662 ,
662− H.reflow $
663+ D.reflow $
663 "Ports need to produce a command (Cmd) or a subscription (Sub) but\
664 "Ports need to produce a command (Cmd) or a subscription (Sub) but\
664 \ this is neither. I do not know how to handle this."
665 \ this is neither. I do not know how to handle this."
665 )
666 )
@@ -675,7 +676,7 @@ toReport source err =
675 Can.TypedDef name _ _ _ _ -> name
676 Can.TypedDef name _ _ _ _ -> name
676
677
677 makeTheory question details =
678 makeTheory question details =
678− H.fillSep $ map (H.dullyellow . H.text) (words question) ++ map H.text (words details)
679+ D.fillSep $ map (D.dullyellow . D.fromString) (words question) ++ map D.fromString (words details)
679 in
680 in
680 case map toName cyclicValueDefs of
681 case map toName cyclicValueDefs of
681 [] ->
682 [] ->
@@ -690,10 +691,10 @@ toReport source err =
690 case map A.toValue otherNames of
691 case map A.toValue otherNames of
691 [] ->
692 [] ->
692 (
693 (
693− H.reflow $
694+ D.reflow $
694 "The `" <> N.toString name <> "` value is defined directly in terms of itself, causing an infinite loop."
695 "The `" <> N.toString name <> "` value is defined directly in terms of itself, causing an infinite loop."
695 ,
696 ,
696− H.stack
697+ D.stack
697 [ makeTheory "Are you are trying to mutate a variable?" $
698 [ makeTheory "Are you are trying to mutate a variable?" $
698 "Elm does not have mutation, so when I see " ++ N.toString name
699 "Elm does not have mutation, so when I see " ++ N.toString name
699 ++ " defined in terms of " ++ N.toString name
700 ++ " defined in terms of " ++ N.toString name
@@ -702,7 +703,7 @@ toReport source err =
702 "To define " ++ N.toString name ++ " we need to know what " ++ N.toString name
703 "To define " ++ N.toString name ++ " we need to know what " ++ N.toString name
703 ++ " is, so let’s expand it. Wait, but now we need to know what " ++ N.toString name
704 ++ " is, so let’s expand it. Wait, but now we need to know what " ++ N.toString name
704 ++ " is, so let’s expand it... This will keep going infinitely!"
705 ++ " is, so let’s expand it... This will keep going infinitely!"
705− , H.link "Hint"
706+ , D.link "Hint"
706 "The root problem is often a typo in some variable name, but I recommend reading"
707 "The root problem is often a typo in some variable name, but I recommend reading"
707 "bad-recursion"
708 "bad-recursion"
708 "for more detailed advice, especially if you actually do need a recursive value."
709 "for more detailed advice, especially if you actually do need a recursive value."
@@ -711,15 +712,15 @@ toReport source err =
711
712
712 names ->
713 names ->
713 (
714 (
714− H.reflow $
715+ D.reflow $
715 "The `" <> N.toString name <> "` definition is causing a very tricky infinite loop."
716 "The `" <> N.toString name <> "` definition is causing a very tricky infinite loop."
716 ,
717 ,
717− H.stack
718+ D.stack
718− [ H.reflow $
719+ [ D.reflow $
719 "The `" <> N.toString name
720 "The `" <> N.toString name
720 <> "` value depends on itself through the following chain of definitions:"
721 <> "` value depends on itself through the following chain of definitions:"
721− , H.indent 4 $ H.drawCycle (name:names)
722+ , D.cycle 4 (name:names)
722− , H.link "Hint"
723+ , D.link "Hint"
723 "The root problem is often a typo in some variable name, but I recommend reading"
724 "The root problem is often a typo in some variable name, but I recommend reading"
724 "bad-recursion"
725 "bad-recursion"
725 "for more detailed advice, especially if you actually do want mutually recursive values."
726 "for more detailed advice, especially if you actually do want mutually recursive values."
@@ -733,13 +734,13 @@ toReport source err =
733 [] ->
734 [] ->
734 let
735 let
735 makeTheory question details =
736 makeTheory question details =
736− H.fillSep $ map (H.dullyellow . H.text) (words question) ++ map H.text (words details)
737+ D.fillSep $ map (D.dullyellow . D.fromString) (words question) ++ map D.fromString (words details)
737 in
738 in
738 (
739 (
739− H.reflow $
740+ D.reflow $
740 "The `" <> N.toString name <> "` value is defined directly in terms of itself, causing an infinite loop."
741 "The `" <> N.toString name <> "` value is defined directly in terms of itself, causing an infinite loop."
741 ,
742 ,
742− H.stack
743+ D.stack
743 [ makeTheory "Are you are trying to mutate a variable?" $
744 [ makeTheory "Are you are trying to mutate a variable?" $
744 "Elm does not have mutation, so when I see " ++ N.toString name
745 "Elm does not have mutation, so when I see " ++ N.toString name
745 ++ " defined in terms of " ++ N.toString name
746 ++ " defined in terms of " ++ N.toString name
@@ -748,7 +749,7 @@ toReport source err =
748 "To define " ++ N.toString name ++ " we need to know what " ++ N.toString name
749 "To define " ++ N.toString name ++ " we need to know what " ++ N.toString name
749 ++ " is, so let’s expand it. Wait, but now we need to know what " ++ N.toString name
750 ++ " is, so let’s expand it. Wait, but now we need to know what " ++ N.toString name
750 ++ " is, so let’s expand it... This will keep going infinitely!"
751 ++ " is, so let’s expand it... This will keep going infinitely!"
751− , H.link "Hint"
752+ , D.link "Hint"
752 "The root problem is often a typo in some variable name, but I recommend reading"
753 "The root problem is often a typo in some variable name, but I recommend reading"
753 "bad-recursion"
754 "bad-recursion"
754 "for more detailed advice, especially if you actually do need a recursive value."
755 "for more detailed advice, especially if you actually do need a recursive value."
@@ -757,15 +758,15 @@ toReport source err =
757
758
758 _ ->
759 _ ->
759 (
760 (
760− H.reflow $
761+ D.reflow $
761 "I do not allow cyclic values in `let` expressions."
762 "I do not allow cyclic values in `let` expressions."
762 ,
763 ,
763− H.stack
764+ D.stack
764− [ H.reflow $
765+ [ D.reflow $
765 "The `" <> N.toString name
766 "The `" <> N.toString name
766 <> "` value depends on itself through the following chain of definitions:"
767 <> "` value depends on itself through the following chain of definitions:"
767− , H.indent 4 $ H.drawCycle (name:names)
768+ , D.cycle 4 (name:names)
768− , H.link "Hint"
769+ , D.link "Hint"
769 "The root problem is often a typo in some variable name, but I recommend reading"
770 "The root problem is often a typo in some variable name, but I recommend reading"
770 "bad-recursion"
771 "bad-recursion"
771 "for more detailed advice, especially if you actually do want mutually recursive values."
772 "for more detailed advice, especially if you actually do want mutually recursive values."
@@ -778,16 +779,16 @@ toReport source err =
778 ( "These variables cannot have the same name:"
779 ( "These variables cannot have the same name:"
779 , advice
780 , advice
780 )
781 )
781− ( H.reflow $ "The name `" <> N.toString name <> "` is first defined here:"
782+ ( D.reflow $ "The name `" <> N.toString name <> "` is first defined here:"
782 , "But then it is defined AGAIN over here:"
783 , "But then it is defined AGAIN over here:"
783 , advice
784 , advice
784 )
785 )
785 where
786 where
786 advice =
787 advice =
787− H.stack
788+ D.stack
788− [ H.reflow $
789+ [ D.reflow $
789 "Think of a more helpful name for one of them and you should be all set!"
790 "Think of a more helpful name for one of them and you should be all set!"
790− , H.link "Note"
791+ , D.link "Note"
791 "Linters advise against shadowing, so Elm makes “best practices” the default. Read"
792 "Linters advise against shadowing, so Elm makes “best practices” the default. Read"
792 "shadowing"
793 "shadowing"
793 "for more details on this choice."
794 "for more details on this choice."
@@ -799,12 +800,12 @@ toReport source err =
799 (
800 (
800 "I only accept tuples with two or three items. This has too many:"
801 "I only accept tuples with two or three items. This has too many:"
801 ,
802 ,
802− H.stack
803+ D.stack
803− [ H.reflow $
804+ [ D.reflow $
804 "I recommend switching to records. Each item will be named, and you can use\
805 "I recommend switching to records. Each item will be named, and you can use\
805 \ the `point.x` syntax to access them."
806 \ the `point.x` syntax to access them."
806
807
807− , H.link "Note" "Read" "tuples"
808+ , D.link "Note" "Read" "tuples"
808
809
809 "for more comprehensive advice on working with large chunks of data in Elm."
810 "for more comprehensive advice on working with large chunks of data in Elm."
810 ]
811 ]
@@ -818,7 +819,7 @@ toReport source err =
818 (unused:unuseds, []) ->
819 (unused:unuseds, []) ->
819 let
820 let
820 backQuote name =
821 backQuote name =
821− "`" <> H.nameToDoc name <> "`"
822+ "`" <> D.fromName name <> "`"
822
823
823 allUnusedNames =
824 allUnusedNames =
824 map fst unusedVars
825 map fst unusedVars
@@ -831,31 +832,31 @@ toReport source err =
831 , ["Type","alias",backQuote typeName,"does","not","use","the"
832 , ["Type","alias",backQuote typeName,"does","not","use","the"
832 ,backQuote (fst unused),"type","variable."
833 ,backQuote (fst unused),"type","variable."
833 ]
834 ]
834− , [H.dullyellow (backQuote (fst unused))]
835+ , [D.dullyellow (backQuote (fst unused))]
835 )
836 )
836
837
837 _:_ ->
838 _:_ ->
838 ( "UNUSED TYPE VARIABLES"
839 ( "UNUSED TYPE VARIABLES"
839 , Nothing
840 , Nothing
840 , ["Type","variables"]
841 , ["Type","variables"]
841− ++ H.commaSep "and" id (map H.nameToDoc allUnusedNames)
842+ ++ D.commaSep "and" id (map D.fromName allUnusedNames)
842 ++ ["are","unused","in","the",backQuote typeName,"definition."]
843 ++ ["are","unused","in","the",backQuote typeName,"definition."]
843− , H.commaSep "and" H.dullyellow (map H.nameToDoc allUnusedNames)
844+ , D.commaSep "and" D.dullyellow (map D.fromName allUnusedNames)
844 )
845 )
845 in
846 in
846 Report.Report title aliasRegion [] $
847 Report.Report title aliasRegion [] $
847 Report.toCodeSnippet source aliasRegion subRegion
848 Report.toCodeSnippet source aliasRegion subRegion
848 (
849 (
849− H.fillSep overview
850+ D.fillSep overview
850 ,
851 ,
851− H.stack
852+ D.stack
852− [ H.fillSep $
853+ [ D.fillSep $
853 ["I","recommend","removing"] ++ stuff ++ ["from","the","declaration,","like","this:"]
854 ["I","recommend","removing"] ++ stuff ++ ["from","the","declaration,","like","this:"]
854− , H.indent 4 $ H.hsep $
855+ , D.indent 4 $ D.hsep $
855− ["type","alias",H.green (H.nameToDoc typeName)]
856+ ["type","alias",D.green (D.fromName typeName)]
856− ++ map H.nameToDoc (filter (`notElem` allUnusedNames) allVars)
857+ ++ map D.fromName (filter (`notElem` allUnusedNames) allVars)
857 ++ ["=", "..."]
858 ++ ["=", "..."]
858− , H.reflow $
859+ , D.reflow $
859 "Why? Well, if I allowed `type alias Height a = Float` I would need to answer\
860 "Why? Well, if I allowed `type alias Height a = Float` I would need to answer\
860 \ some weird questions. Is `Height Bool` the same as `Float`? Is `Height Bool`\
861 \ some weird questions. Is `Height Bool` the same as `Float`? Is `Height Bool`\
861 \ the same as `Height Int`? My solution is to not need to ask them!"
862 \ the same as `Height Int`? My solution is to not need to ask them!"
@@ -873,43 +874,43 @@ toReport source err =
873 theseAreUsed =
874 theseAreUsed =
874 case unbound of
875 case unbound of
875 [x] ->
876 [x] ->
876− ["Type","variable",H.dullyellow ("`" <> H.nameToDoc x <> "`"),"appears"
877+ ["Type","variable",D.dullyellow ("`" <> D.fromName x <> "`"),"appears"
877 ,"in","the","definition,","but","I","do","not","see","it","declared."
878 ,"in","the","definition,","but","I","do","not","see","it","declared."
878 ]
879 ]
879
880
880 _ ->
881 _ ->
881 ["Type","variables"]
882 ["Type","variables"]
882− ++ H.commaSep "and" H.dullyellow (map H.nameToDoc unbound)
883+ ++ D.commaSep "and" D.dullyellow (map D.fromName unbound)
883 ++ ["are","used","in","the","definition,","but","I","do","not","see","them","declared."]
884 ++ ["are","used","in","the","definition,","but","I","do","not","see","them","declared."]
884
885
885 butTheseAreUnused =
886 butTheseAreUnused =
886 case unused of
887 case unused of
887 [x] ->
888 [x] ->
888 ["Likewise,","type","variable"
889 ["Likewise,","type","variable"
889− ,H.dullyellow ("`" <> H.nameToDoc x <> "`")
890+ ,D.dullyellow ("`" <> D.fromName x <> "`")
890 ,"is","delared,","but","not","used."
891 ,"is","delared,","but","not","used."
891 ]
892 ]
892
893
893 _ ->
894 _ ->
894 ["Likewise,","type","variables"]
895 ["Likewise,","type","variables"]
895− ++ H.commaSep "and" H.dullyellow (map H.nameToDoc unused)
896+ ++ D.commaSep "and" D.dullyellow (map D.fromName unused)
896 ++ ["are","delared,","but","not","used."]
897 ++ ["are","delared,","but","not","used."]
897
898
898 in
899 in
899 Report.Report "TYPE VARIABLE PROBLEMS" aliasRegion [] $
900 Report.Report "TYPE VARIABLE PROBLEMS" aliasRegion [] $
900 Report.toCodeSnippet source aliasRegion Nothing
901 Report.toCodeSnippet source aliasRegion Nothing
901 (
902 (
902− H.reflow $
903+ D.reflow $
903 "Type alias `" <> N.toString typeName <> "` has some type variable problems."
904 "Type alias `" <> N.toString typeName <> "` has some type variable problems."
904 ,
905 ,
905− H.stack
906+ D.stack
906− [ H.fillSep $ theseAreUsed ++ butTheseAreUnused
907+ [ D.fillSep $ theseAreUsed ++ butTheseAreUnused
907− , H.reflow $
908+ , D.reflow $
908 "My guess is that a definition like this will work better:"
909 "My guess is that a definition like this will work better:"
909− , H.indent 4 $ H.hsep $
910+ , D.indent 4 $ D.hsep $
910− ["type", "alias", H.nameToDoc typeName]
911+ ["type", "alias", D.fromName typeName]
911− ++ map H.nameToDoc (filter (`notElem` unused) allVars)
912+ ++ map D.fromName (filter (`notElem` unused) allVars)
912− ++ map (H.green . H.nameToDoc) unbound
913+ ++ map (D.green . D.fromName) unbound
913 ++ ["=", "..."]
914 ++ ["=", "..."]
914 ]
915 ]
915 )
916 )
@@ -919,11 +920,11 @@ toReport source err =
919-- BAD TYPE VARIABLES
920-- BAD TYPE VARIABLES
920
921
921
922
922−unboundTypeVars :: Code.Source -> R.Region -> [H.Doc] -> N.Name -> [N.Name] -> (N.Name, R.Region) -> [(N.Name, R.Region)] -> Report.Report
923+unboundTypeVars :: Code.Source -> R.Region -> [D.Doc] -> N.Name -> [N.Name] -> (N.Name, R.Region) -> [(N.Name, R.Region)] -> Report.Report
923unboundTypeVars source declRegion tipe typeName allVars (unboundVar, varRegion) unboundVars =
924unboundTypeVars source declRegion tipe typeName allVars (unboundVar, varRegion) unboundVars =
924 let
925 let
925 backQuote name =
926 backQuote name =
926− "`" <> H.nameToDoc name <> "`"
927+ "`" <> D.fromName name <> "`"
927
928
928 (title, subRegion, overview) =
929 (title, subRegion, overview) =
929 case map fst unboundVars of
930 case map fst unboundVars of
@@ -932,32 +933,32 @@ unboundTypeVars source declRegion tipe typeName allVars (unboundVar, varRegion)
932 , Just varRegion
933 , Just varRegion
933 , ["The",backQuote typeName]
934 , ["The",backQuote typeName]
934 ++ tipe
935 ++ tipe
935− ++ ["uses","an","unbound","type","variable",H.dullyellow (backQuote unboundVar),"in","its","definition:"]
936+ ++ ["uses","an","unbound","type","variable",D.dullyellow (backQuote unboundVar),"in","its","definition:"]
936 )
937 )
937
938
938 vars ->
939 vars ->
939 ( "UNBOUND TYPE VARIABLES"
940 ( "UNBOUND TYPE VARIABLES"
940 , Nothing
941 , Nothing
941 , ["Type","variables"]
942 , ["Type","variables"]
942− ++ H.commaSep "and" H.dullyellow (H.nameToDoc unboundVar : map H.nameToDoc vars)
943+ ++ D.commaSep "and" D.dullyellow (D.fromName unboundVar : map D.fromName vars)
943 ++ ["are","unbound","in","the",backQuote typeName] ++ tipe ++ ["definition:"]
944 ++ ["are","unbound","in","the",backQuote typeName] ++ tipe ++ ["definition:"]
944 )
945 )
945 in
946 in
946 Report.Report title declRegion [] $
947 Report.Report title declRegion [] $
947 Report.toCodeSnippet source declRegion subRegion
948 Report.toCodeSnippet source declRegion subRegion
948 (
949 (
949− H.fillSep overview
950+ D.fillSep overview
950 ,
951 ,
951− H.stack
952+ D.stack
952− [ H.reflow $
953+ [ D.reflow $
953 "You probably need to change the declaration to something like this:"
954 "You probably need to change the declaration to something like this:"
954− , H.indent 4 $ H.hsep $
955+ , D.indent 4 $ D.hsep $
955 tipe
956 tipe
956− ++ [H.nameToDoc typeName]
957+ ++ [D.fromName typeName]
957− ++ map H.nameToDoc allVars
958+ ++ map D.fromName allVars
958− ++ map (H.green . H.nameToDoc) (unboundVar : map fst unboundVars)
959+ ++ map (D.green . D.fromName) (unboundVar : map fst unboundVars)
959 ++ ["=", "..."]
960 ++ ["=", "..."]
960− , H.reflow $
961+ , D.reflow $
961 "Why? Well, imagine one `" ++ N.toString typeName ++ "` where `" ++ N.toString unboundVar ++
962 "Why? Well, imagine one `" ++ N.toString typeName ++ "` where `" ++ N.toString unboundVar ++
962 "` is an Int and another where it is a Bool. When we explicitly list the type\
963 "` is an Int and another where it is a Bool. When we explicitly list the type\
963 \ variables, the type checker can see that they are actually different types."
964 \ variables, the type checker can see that they are actually different types."
@@ -974,12 +975,12 @@ nameClash source r1 r2 messageThatEndsWithPunctuation =
974 Report.Report "NAME CLASH" r2 [] $
975 Report.Report "NAME CLASH" r2 [] $
975 Report.toCodePair source r1 r2
976 Report.toCodePair source r1 r2
976 (
977 (
977− H.reflow messageThatEndsWithPunctuation
978+ D.reflow messageThatEndsWithPunctuation
978 ,
979 ,
979 "How can I know which one you want? Rename one of them!"
980 "How can I know which one you want? Rename one of them!"
980 )
981 )
981 (
982 (
982− H.reflow (messageThatEndsWithPunctuation <> " One here:")
983+ D.reflow (messageThatEndsWithPunctuation <> " One here:")
983 ,
984 ,
984 "And another one here:"
985 "And another one here:"
985 ,
986 ,
@@ -999,20 +1000,20 @@ ambiguousName source region maybePrefix name possibleHomes thing =
999 Nothing ->
1000 Nothing ->
1000 let
1001 let
1001 homeToYellowDoc (ModuleName.Canonical _ home) =
1002 homeToYellowDoc (ModuleName.Canonical _ home) =
1002− H.dullyellow (H.nameToDoc home)
1003+ D.dullyellow (D.fromName home)
1003
1004
1004 bothOrAll =
1005 bothOrAll =
1005 if length possibleHomes == 2 then "both" else "all"
1006 if length possibleHomes == 2 then "both" else "all"
1006 in
1007 in
1007 (
1008 (
1008− H.reflow $ "This usage of `" ++ N.toString name ++ "` is ambiguous."
1009+ D.reflow $ "This usage of `" ++ N.toString name ++ "` is ambiguous."
1009 ,
1010 ,
1010− H.stack
1011+ D.stack
1011− [ H.reflow $
1012+ [ D.reflow $
1012 "Check your imports. The following modules " ++ bothOrAll
1013 "Check your imports. The following modules " ++ bothOrAll
1013 ++ " expose a `" ++ N.toString name ++ "` " ++ thing ++ ":"
1014 ++ " expose a `" ++ N.toString name ++ "` " ++ thing ++ ":"
1014− , H.indent 4 $ H.vcat $ map homeToYellowDoc possibleHomes
1015+ , D.indent 4 $ D.vcat $ map homeToYellowDoc possibleHomes
1015− , H.reflowLink "Read" "imports" "to learn how to clarify which one you want."
1016+ , D.reflowLink "Read" "imports" "to learn how to clarify which one you want."
1016 ]
1017 ]
1017 )
1018 )
1018
1019
@@ -1020,22 +1021,22 @@ ambiguousName source region maybePrefix name possibleHomes thing =
1020 let
1021 let
1021 homeToYellowDoc (ModuleName.Canonical _ home) =
1022 homeToYellowDoc (ModuleName.Canonical _ home) =
1022 if prefix == home then
1023 if prefix == home then
1023− H.blue "import" <+> H.dullyellow (H.nameToDoc home)
1024+ D.blue "import" <+> D.dullyellow (D.fromName home)
1024 else
1025 else
1025− H.blue "import" <+> H.dullyellow (H.nameToDoc home) <+> H.blue "as" <+> H.dullyellow (H.nameToDoc prefix)
1026+ D.blue "import" <+> D.dullyellow (D.fromName home) <+> D.blue "as" <+> D.dullyellow (D.fromName prefix)
1026
1027
1027 eitherOrAny =
1028 eitherOrAny =
1028 if length possibleHomes == 2 then "either" else "any"
1029 if length possibleHomes == 2 then "either" else "any"
1029 in
1030 in
1030 (
1031 (
1031− H.reflow $ "This usage of `" ++ toQualString prefix name ++ "` is ambiguous."
1032+ D.reflow $ "This usage of `" ++ toQualString prefix name ++ "` is ambiguous."
1032 ,
1033 ,
1033− H.stack
1034+ D.stack
1034− [ H.reflow $
1035+ [ D.reflow $
1035 "It could refer to a " ++ thing ++ " from "
1036 "It could refer to a " ++ thing ++ " from "
1036 ++ eitherOrAny ++ " of these imports:"
1037 ++ eitherOrAny ++ " of these imports:"
1037− , H.indent 4 $ H.vcat $ map homeToYellowDoc possibleHomes
1038+ , D.indent 4 $ D.vcat $ map homeToYellowDoc possibleHomes
1038− , H.reflowLink "Read" "imports" "to learn how to clarify which one you want."
1039+ , D.reflowLink "Read" "imports" "to learn how to clarify which one you want."
1039 ]
1040 ]
1040 )
1041 )
1041
1042
@@ -1058,28 +1059,28 @@ notFound source region maybePrefix name thing (PossibleNames locals quals) =
1058 Map.foldrWithKey addQuals (map N.toString (Set.toList locals)) quals
1059 Map.foldrWithKey addQuals (map N.toString (Set.toList locals)) quals
1059
1060
1060 nearbyNames =
1061 nearbyNames =
1061− take 4 (H.nearbyNames id givenName possibleNames)
1062+ take 4 (Suggest.nearbyNames id givenName possibleNames)
1062
1063
1063 toDetails noSuggestionDetails yesSuggestionDetails =
1064 toDetails noSuggestionDetails yesSuggestionDetails =
1064 case nearbyNames of
1065 case nearbyNames of
1065 [] ->
1066 [] ->
1066− H.stack
1067+ D.stack
1067− [ H.reflow noSuggestionDetails
1068+ [ D.reflow noSuggestionDetails
1068− , H.link "Hint" "Read" "imports" "to see how `import` declarations work in Elm."
1069+ , D.link "Hint" "Read" "imports" "to see how `import` declarations work in Elm."
1069 ]
1070 ]
1070
1071
1071 suggestions ->
1072 suggestions ->
1072− H.stack
1073+ D.stack
1073− [ H.reflow yesSuggestionDetails
1074+ [ D.reflow yesSuggestionDetails
1074− , H.indent 4 $ H.vcat $ map H.dullyellow $ map H.text suggestions
1075+ , D.indent 4 $ D.vcat $ map D.dullyellow $ map D.fromString suggestions
1075− , H.link "Hint" "Read" "imports" "to see how `import` declarations work in Elm."
1076+ , D.link "Hint" "Read" "imports" "to see how `import` declarations work in Elm."
1076 ]
1077 ]
1077
1078
1078 in
1079 in
1079 Report.Report "NAMING ERROR" region nearbyNames $
1080 Report.Report "NAMING ERROR" region nearbyNames $
1080 Report.toCodeSnippet source region Nothing
1081 Report.toCodeSnippet source region Nothing
1081 (
1082 (
1082− H.reflow $
1083+ D.reflow $
1083 "I cannot find a `" ++ givenName ++ "` " ++ thing ++ ":"
1084 "I cannot find a `" ++ givenName ++ "` " ++ thing ++ ":"
1084 ,
1085 ,
1085 case maybePrefix of
1086 case maybePrefix of
@@ -1115,20 +1116,20 @@ varErrorToReport :: VarError -> Report.Report
1115varErrorToReport (VarError kind name problem suggestions) =
1116varErrorToReport (VarError kind name problem suggestions) =
1116 let
1117 let
1117 learnMore orMaybe =
1118 learnMore orMaybe =
1118− H.reflow $
1119+ D.reflow $
1119 orMaybe <> " `import` works different than you expect? Learn all about it here: "
1120 orMaybe <> " `import` works different than you expect? Learn all about it here: "
1120− <> H.hintLink "imports"
1121+ <> D.hintLink "imports"
1121
1122
1122 namingError overview maybeStarter specializedSuggestions =
1123 namingError overview maybeStarter specializedSuggestions =
1123 Report.reportDoc "NAMING ERROR" Nothing overview $
1124 Report.reportDoc "NAMING ERROR" Nothing overview $
1124− case H.maybeYouWant' maybeStarter specializedSuggestions of
1125+ case D.maybeYouWant' maybeStarter specializedSuggestions of
1125 Nothing ->
1126 Nothing ->
1126 learnMore "Maybe"
1127 learnMore "Maybe"
1127 Just doc ->
1128 Just doc ->
1128− H.stack [ doc, learnMore "Or maybe" ]
1129+ D.stack [ doc, learnMore "Or maybe" ]
1129
1130
1130 specialNamingError specialHint =
1131 specialNamingError specialHint =
1131− Report.reportDoc "NAMING ERROR" Nothing (cannotFind kind name) (H.hsep specialHint)
1132+ Report.reportDoc "NAMING ERROR" Nothing (cannotFind kind name) (D.hsep specialHint)
1132 in
1133 in
1133 case problem of
1134 case problem of
1134 Ambiguous ->
1135 Ambiguous ->
@@ -1158,35 +1159,35 @@ varErrorToReport (VarError kind name problem suggestions) =
1158cannotFind :: VarKind -> Text -> [Doc]
1159cannotFind :: VarKind -> Text -> [Doc]
1159cannotFind kind rawName =
1160cannotFind kind rawName =
1160 let ( a, thing, name ) = toKindInfo kind rawName in
1161 let ( a, thing, name ) = toKindInfo kind rawName in
1161− [ "Cannot", "find", a, thing, "named", H.dullyellow name <> ":" ]
1162+ [ "Cannot", "find", a, thing, "named", D.dullyellow name <> ":" ]
1162
1163
1163
1164
1164ambiguous :: VarKind -> Text -> [Doc]
1165ambiguous :: VarKind -> Text -> [Doc]
1165ambiguous kind rawName =
1166ambiguous kind rawName =
1166 let ( _a, thing, name ) = toKindInfo kind rawName in
1167 let ( _a, thing, name ) = toKindInfo kind rawName in
1167− [ "This", "usage", "of", "the", H.dullyellow name, thing, "is", "ambiguous." ]
1168+ [ "This", "usage", "of", "the", D.dullyellow name, thing, "is", "ambiguous." ]
1168
1169
1169
1170
1170notEqualsHint :: Text -> [Doc]
1171notEqualsHint :: Text -> [Doc]
1171notEqualsHint op =
1172notEqualsHint op =
1172 [ "Looking", "for", "the", "“not", "equal”", "operator?", "The", "traditional"
1173 [ "Looking", "for", "the", "“not", "equal”", "operator?", "The", "traditional"
1173− , H.dullyellow $ text $ "(" <> op <> ")"
1174+ , D.dullyellow $ text $ "(" <> op <> ")"
1174− , "is", "replaced", "by", H.green "(/=)", "in", "Elm.", "It", "is", "meant"
1175+ , "is", "replaced", "by", D.green "(/=)", "in", "Elm.", "It", "is", "meant"
1175 , "to", "look", "like", "the", "“not", "equal”", "sign", "from", "math!", "(≠)"
1176 , "to", "look", "like", "the", "“not", "equal”", "sign", "from", "math!", "(≠)"
1176 ]
1177 ]
1177
1178
1178
1179
1179equalsHint :: [Doc]
1180equalsHint :: [Doc]
1180equalsHint =
1181equalsHint =
1181− [ "A", "special", H.dullyellow "(===)", "operator", "is", "not", "needed"
1182+ [ "A", "special", D.dullyellow "(===)", "operator", "is", "not", "needed"
1182− , "in", "Elm.", "We", "use", H.green "(==)", "for", "everything!"
1183+ , "in", "Elm.", "We", "use", D.green "(==)", "for", "everything!"
1183 ]
1184 ]
1184
1185
1185
1186
1186modHint :: [Doc]
1187modHint :: [Doc]
1187modHint =
1188modHint =
1188− [ "Rather", "than", "a", H.dullyellow "(%)", "operator,"
1189+ [ "Rather", "than", "a", D.dullyellow "(%)", "operator,"
1189− , "Elm", "has", "a", H.green "modBy", "function."
1190+ , "Elm", "has", "a", D.green "modBy", "function."
1190 , "Learn", "more", "here:"
1191 , "Learn", "more", "here:"
1191 , "<https://package.elm-lang.org/packages/elm-lang/core/latest/Basics#modBy>"
1192 , "<https://package.elm-lang.org/packages/elm-lang/core/latest/Basics#modBy>"
1192 ]
1193 ]
@@ -1209,10 +1210,10 @@ _argMismatchReport source region kind name expected actual =
1209 Report.Report (map Char.toUpper numArgs) region [] $
1210 Report.Report (map Char.toUpper numArgs) region [] $
1210 Report.toCodeSnippet source region Nothing
1211 Report.toCodeSnippet source region Nothing
1211 (
1212 (
1212− H.reflow $
1213+ D.reflow $
1213 kind <> " " <> N.toString name <> " has " <> numArgs <> "."
1214 kind <> " " <> N.toString name <> " has " <> numArgs <> "."
1214 ,
1215 ,
1215− H.reflow $
1216+ D.reflow $
1216 "Expecting " <> show expected <> ", but got " <> show actual <> "."
1217 "Expecting " <> show expected <> ", but got " <> show actual <> "."
1217 )
1218 )
1218
1219
@@ -1230,13 +1231,13 @@ aliasRecursionReport source region name args tipe others =
1230 (
1231 (
1231 "This type alias is recursive, forming an infinite type!"
1232 "This type alias is recursive, forming an infinite type!"
1232 ,
1233 ,
1233− H.stack
1234+ D.stack
1234− [ H.reflow $
1235+ [ D.reflow $
1235 "When I expand a recursive type alias, it just keeps getting bigger and bigger.\
1236 "When I expand a recursive type alias, it just keeps getting bigger and bigger.\
1236 \ So dealiasing results in an infinitely large type! Try this instead:"
1237 \ So dealiasing results in an infinitely large type! Try this instead:"
1237− , H.indent 4 $
1238+ , D.indent 4 $
1238 aliasToUnionDoc name args tipe
1239 aliasToUnionDoc name args tipe
1239− , H.link "Hint"
1240+ , D.link "Hint"
1240 "This is kind of a subtle distinction. I suggested the naive fix, but I recommend reading"
1241 "This is kind of a subtle distinction. I suggested the naive fix, but I recommend reading"
1241 "recursive-alias"
1242 "recursive-alias"
1242 "for ideas on how to do better."
1243 "for ideas on how to do better."
@@ -1249,12 +1250,12 @@ aliasRecursionReport source region name args tipe others =
1249 (
1250 (
1250 "This type alias is part of a mutually recursive set of type aliases."
1251 "This type alias is part of a mutually recursive set of type aliases."
1251 ,
1252 ,
1252− H.stack
1253+ D.stack
1253 [ "It is part of this cycle of type aliases:"
1254 [ "It is part of this cycle of type aliases:"
1254− , H.indent 4 (H.drawCycle (name:others))
1255+ , D.cycle 4 (name:others)
1255− , H.reflow $
1256+ , D.reflow $
1256 "You need to convert at least one of these type aliases into a `type`."
1257 "You need to convert at least one of these type aliases into a `type`."
1257− , H.link "Note" "Read" "recursive-alias"
1258+ , D.link "Note" "Read" "recursive-alias"
1258 "to learn why this `type` vs `type alias` distinction matters. It is subtle but important!"
1259 "to learn why this `type` vs `type alias` distinction matters. It is subtle but important!"
1259 ]
1260 ]
1260 )
1261 )
@@ -1262,11 +1263,11 @@ aliasRecursionReport source region name args tipe others =
1262
1263
1263aliasToUnionDoc :: N.Name -> [N.Name] -> Src.Type -> Doc
1264aliasToUnionDoc :: N.Name -> [N.Name] -> Src.Type -> Doc
1264aliasToUnionDoc name args tipe =
1265aliasToUnionDoc name args tipe =
1265− H.vcat
1266+ D.vcat
1266− [ H.dullyellow $
1267+ [ D.dullyellow $
1267− "type" <+> H.nameToDoc name <+> (foldr (<+>) "=" (map H.nameToDoc args))
1268+ "type" <+> D.fromName name <+> (foldr (<+>) "=" (map D.fromName args))
1268− , H.green $
1269+ , D.green $
1269− H.indent 4 (H.nameToDoc name)
1270+ D.indent 4 (D.fromName name)
1270− , H.dullyellow $
1271+ , D.dullyellow $
1271− H.indent 8 (RT.srcToDoc RT.App tipe)
1272+ D.indent 8 (RT.srcToDoc RT.App tipe)
1272 ]
1273 ]
compiler/src/Reporting/Error/Docs.hs+24−24
@@ -8,8 +8,8 @@ module Reporting.Error.Docs
8
8
9
9
10import qualified Elm.Name as N
10import qualified Elm.Name as N
11−import Reporting.Helpers ((<>))
11+import Reporting.Doc ((<>))
12−import qualified Reporting.Helpers as H
12+import qualified Reporting.Doc as D
13import qualified Reporting.Region as R
13import qualified Reporting.Region as R
14import qualified Reporting.Render.Code as Code
14import qualified Reporting.Render.Code as Code
15import qualified Reporting.Report as Report
15import qualified Reporting.Report as Report
@@ -35,24 +35,24 @@ toReport source err =
35 case err of
35 case err of
36 NoDocs region ->
36 NoDocs region ->
37 Report.Report "NO DOCS" region [] $
37 Report.Report "NO DOCS" region [] $
38− H.stack
38+ D.stack
39 [
39 [
40− H.reflow $
40+ D.reflow $
41 "You must have a documentation comment between the module\
41 "You must have a documentation comment between the module\
42 \ declaration and the imports."
42 \ declaration and the imports."
43 ,
43 ,
44− H.reflow
44+ D.reflow
45 "Learn more at <http://package.elm-lang.org/help/documentation-format>"
45 "Learn more at <http://package.elm-lang.org/help/documentation-format>"
46 ]
46 ]
47
47
48 ImplicitExposing region ->
48 ImplicitExposing region ->
49 Report.Report "IMPLICIT EXPOSING" region [] $
49 Report.Report "IMPLICIT EXPOSING" region [] $
50− H.stack
50+ D.stack
51 [
51 [
52− H.reflow $
52+ D.reflow $
53 "I need you to be explicit about what this module exposes:"
53 "I need you to be explicit about what this module exposes:"
54 ,
54 ,
55− H.reflow $
55+ D.reflow $
56 "A great API usually hides some implementation details, so it is rare that\
56 "A great API usually hides some implementation details, so it is rare that\
57 \ everything in the file should be exposed. And requiring package authors\
57 \ everything in the file should be exposed. And requiring package authors\
58 \ to be explicit about this is a way of adding another quality check before\
58 \ to be explicit about this is a way of adding another quality check before\
@@ -64,14 +64,14 @@ toReport source err =
64 Report.Report "DUPLICATE DOCS" r2 [] $
64 Report.Report "DUPLICATE DOCS" r2 [] $
65 Report.toCodePair source r1 r2
65 Report.toCodePair source r1 r2
66 (
66 (
67− H.reflow $
67+ D.reflow $
68 "There can only be one `" <> N.toString name
68 "There can only be one `" <> N.toString name
69 <> "` in your module documentation, but it is listed twice:"
69 <> "` in your module documentation, but it is listed twice:"
70 ,
70 ,
71 "Remove one of them!"
71 "Remove one of them!"
72 )
72 )
73 (
73 (
74− H.reflow $
74+ D.reflow $
75 "There can only be one `" <> N.toString name
75 "There can only be one `" <> N.toString name
76 <> "` in your module documentation, but I see two. One here:"
76 <> "` in your module documentation, but I see two. One here:"
77 ,
77 ,
@@ -84,11 +84,11 @@ toReport source err =
84 Report.Report "DOCS MISTAKE" region [] $
84 Report.Report "DOCS MISTAKE" region [] $
85 Report.toCodeSnippet source region Nothing
85 Report.toCodeSnippet source region Nothing
86 (
86 (
87− H.reflow $
87+ D.reflow $
88 "I do not see `" <> N.toString name
88 "I do not see `" <> N.toString name
89 <> "` in the `exposing` list, but it is in your module documentation:"
89 <> "` in the `exposing` list, but it is in your module documentation:"
90 ,
90 ,
91− H.reflow $
91+ D.reflow $
92 "Does it need to be added to the `exposing` list as well? Or maybe you removed `"
92 "Does it need to be added to the `exposing` list as well? Or maybe you removed `"
93 <> N.toString name <> "` and forgot to delete it here?"
93 <> N.toString name <> "` and forgot to delete it here?"
94 )
94 )
@@ -97,15 +97,15 @@ toReport source err =
97 Report.Report "DOCS MISTAKE" region [] $
97 Report.Report "DOCS MISTAKE" region [] $
98 Report.toCodeSnippet source region Nothing
98 Report.toCodeSnippet source region Nothing
99 (
99 (
100− H.reflow $
100+ D.reflow $
101 "I do not see `" <> N.toString name
101 "I do not see `" <> N.toString name
102 <> "` in your module documentation, but it is in your `exposing` list:"
102 <> "` in your module documentation, but it is in your `exposing` list:"
103 ,
103 ,
104− H.stack
104+ D.stack
105− [ H.reflow $
105+ [ D.reflow $
106 "Add a line like `@docs " <> N.toString name
106 "Add a line like `@docs " <> N.toString name
107 <> "` to your module documentation!"
107 <> "` to your module documentation!"
108− , H.link "Note" "See" "docs" "for more guidance on writing high quality docs."
108+ , D.link "Note" "See" "docs" "for more guidance on writing high quality docs."
109 ]
109 ]
110 )
110 )
111
111
@@ -113,13 +113,13 @@ toReport source err =
113 Report.Report "NO DOCS" region [] $
113 Report.Report "NO DOCS" region [] $
114 Report.toCodeSnippet source region Nothing
114 Report.toCodeSnippet source region Nothing
115 (
115 (
116− H.reflow $
116+ D.reflow $
117 "The `" <> N.toString name <> "` definition does not have a documentation comment."
117 "The `" <> N.toString name <> "` definition does not have a documentation comment."
118 ,
118 ,
119− H.stack
119+ D.stack
120− [ H.reflow $
120+ [ D.reflow $
121 "Add documentation with nice examples of how to use it!"
121 "Add documentation with nice examples of how to use it!"
122− , H.link "Note" "Read" "docs" "for more advice on writing great docs. There are a couple important tricks!"
122+ , D.link "Note" "Read" "docs" "for more advice on writing great docs. There are a couple important tricks!"
123 ]
123 ]
124 )
124 )
125
125
@@ -127,14 +127,14 @@ toReport source err =
127 Report.Report "NO TYPE ANNOTATION" region [] $
127 Report.Report "NO TYPE ANNOTATION" region [] $
128 Report.toCodeSnippet source region Nothing
128 Report.toCodeSnippet source region Nothing
129 (
129 (
130− H.reflow $
130+ D.reflow $
131 "The `" <> N.toString name <> "` definition does not have a type annotation."
131 "The `" <> N.toString name <> "` definition does not have a type annotation."
132 ,
132 ,
133− H.stack
133+ D.stack
134− [ H.reflow $
134+ [ D.reflow $
135 "I use the type variable names from your annotations when generating docs. So if\
135 "I use the type variable names from your annotations when generating docs. So if\
136 \ you say `Html msg` in your type annotation, I can use `msg` in the docs and make\
136 \ you say `Html msg` in your type annotation, I can use `msg` in the docs and make\
137 \ them a bit clearer. So add an annotation and try to use nice type variables!"
137 \ them a bit clearer. So add an annotation and try to use nice type variables!"
138− , H.link "Note" "Read" "docs" "for more advice on writing great docs. There are a couple important tricks!"
138+ , D.link "Note" "Read" "docs" "for more advice on writing great docs. There are a couple important tricks!"
139 ]
139 ]
140 )
140 )
compiler/src/Reporting/Error/Main.hs+16−16
@@ -9,8 +9,8 @@ module Reporting.Error.Main
9
9
10import qualified AST.Canonical as Can
10import qualified AST.Canonical as Can
11import qualified Elm.Name as N
11import qualified Elm.Name as N
12+import qualified Reporting.Doc as D
12import qualified Reporting.Error.Canonicalize as E
13import qualified Reporting.Error.Canonicalize as E
13−import qualified Reporting.Helpers as H
14import qualified Reporting.Region as R
14import qualified Reporting.Region as R
15import qualified Reporting.Render.Code as Code
15import qualified Reporting.Render.Code as Code
16import qualified Reporting.Render.Type as RT
16import qualified Reporting.Render.Type as RT
@@ -40,10 +40,10 @@ toReport source err =
40 (
40 (
41 "I cannot handle this type of `main` value:"
41 "I cannot handle this type of `main` value:"
42 ,
42 ,
43− H.stack
43+ D.stack
44 [ "The type of `main` value I am seeing is:"
44 [ "The type of `main` value I am seeing is:"
45− , H.indent 4 $ H.dullyellow $ RT.canToDoc RT.None tipe
45+ , D.indent 4 $ D.dullyellow $ RT.canToDoc RT.None tipe
46− , H.reflow $
46+ , D.reflow $
47 "I only know how to handle Html, Svg, and Programs\
47 "I only know how to handle Html, Svg, and Programs\
48 \ though. Modify `main` to be one of those types of values!"
48 \ though. Modify `main` to be one of those types of values!"
49 ]
49 ]
@@ -55,11 +55,11 @@ toReport source err =
55 (
55 (
56 "A `main` definition cannot be defined in terms of itself."
56 "A `main` definition cannot be defined in terms of itself."
57 ,
57 ,
58− H.stack
58+ D.stack
59− [ H.reflow $
59+ [ D.reflow $
60 "It should be a boring value with no recursion. But\
60 "It should be a boring value with no recursion. But\
61 \ instead it is involved in this cycle of definitions:"
61 \ instead it is involved in this cycle of definitions:"
62− , H.indent 4 (H.drawCycle cycleNames)
62+ , D.cycle 4 cycleNames
63 ]
63 ]
64 )
64 )
65
65
@@ -69,7 +69,7 @@ toReport source err =
69 Report.Report "BAD FLAGS" region [] $
69 Report.Report "BAD FLAGS" region [] $
70 Report.toCodeSnippet source region Nothing
70 Report.toCodeSnippet source region Nothing
71 (
71 (
72− H.reflow $
72+ D.reflow $
73 "Your `main` program wants " ++ aBadKindOfThing ++ " from JavaScript."
73 "Your `main` program wants " ++ aBadKindOfThing ++ " from JavaScript."
74 ,
74 ,
75 butThatIsNoGood
75 butThatIsNoGood
@@ -81,7 +81,7 @@ toReport source err =
81 (
81 (
82 "an extended record"
82 "an extended record"
83 ,
83 ,
84− H.reflow $
84+ D.reflow $
85 "But the exact shape of the record must be known at compile time. No type variables!"
85 "But the exact shape of the record must be known at compile time. No type variables!"
86 )
86 )
87
87
@@ -89,7 +89,7 @@ toReport source err =
89 (
89 (
90 "a function"
90 "a function"
91 ,
91 ,
92− H.reflow $
92+ D.reflow $
93 "But if I allowed functions from JS, it would be possible to sneak\
93 "But if I allowed functions from JS, it would be possible to sneak\
94 \ side-effects and runtime exceptions into Elm!"
94 \ side-effects and runtime exceptions into Elm!"
95 )
95 )
@@ -98,7 +98,7 @@ toReport source err =
98 (
98 (
99 "an unspecified type"
99 "an unspecified type"
100 ,
100 ,
101− H.reflow $
101+ D.reflow $
102 "But type variables like `" ++ N.toString name ++ "` cannot be given as flags.\
102 "But type variables like `" ++ N.toString name ++ "` cannot be given as flags.\
103 \ I need to know exactly what type of data I am getting, so I can guarantee that\
103 \ I need to know exactly what type of data I am getting, so I can guarantee that\
104 \ unexpected data cannot sneak in and crash the Elm program."
104 \ unexpected data cannot sneak in and crash the Elm program."
@@ -108,13 +108,13 @@ toReport source err =
108 (
108 (
109 "a `" ++ N.toString name ++ "` value"
109 "a `" ++ N.toString name ++ "` value"
110 ,
110 ,
111− H.stack
111+ D.stack
112− [ H.reflow $ "I cannot handle that. The types that CAN be in flags include:"
112+ [ D.reflow $ "I cannot handle that. The types that CAN be in flags include:"
113− , H.indent 4 $
113+ , D.indent 4 $
114− H.reflow $
114+ D.reflow $
115 "Ints, Floats, Bools, Strings, Maybes, Lists, Arrays,\
115 "Ints, Floats, Bools, Strings, Maybes, Lists, Arrays,\
116 \ tuples, records, and JSON values."
116 \ tuples, records, and JSON values."
117− , H.reflow $
117+ , D.reflow $
118 "Since JSON values can flow through, you can use JSON encoders and decoders\
118 "Since JSON values can flow through, you can use JSON encoders and decoders\
119 \ to allow other types through as well. More advanced users often just do\
119 \ to allow other types through as well. More advanced users often just do\
120 \ everything with encoders and decoders for more control and better errors."
120 \ everything with encoders and decoders for more control and better errors."
compiler/src/Reporting/Error/Pattern.hs+21−21
@@ -9,10 +9,10 @@ module Reporting.Error.Pattern
9import qualified Data.List as List
9import qualified Data.List as List
10
10
11import qualified Nitpick.PatternMatches as P
11import qualified Nitpick.PatternMatches as P
12+import Reporting.Doc ((<>))
13+import qualified Reporting.Doc as D
12import qualified Reporting.Report as Report
14import qualified Reporting.Report as Report
13import qualified Reporting.Render.Code as Code
15import qualified Reporting.Render.Code as Code
14−import qualified Reporting.Helpers as H
15−import Reporting.Helpers ((<>))
16
16
17
17
18
18
@@ -26,10 +26,10 @@ toReport source err =
26 Report.Report "REDUNDANT PATTERN" patternRegion [] $
26 Report.Report "REDUNDANT PATTERN" patternRegion [] $
27 Report.toCodeSnippet source caseRegion (Just patternRegion)
27 Report.toCodeSnippet source caseRegion (Just patternRegion)
28 (
28 (
29− H.reflow $
29+ D.reflow $
30− "The " <> H.ordinalize index <> " pattern is redundant:"
30+ "The " <> D.ordinalize index <> " pattern is redundant:"
31 ,
31 ,
32− H.reflow $
32+ D.reflow $
33 "Any value with this shape will be handled by a previous\
33 "Any value with this shape will be handled by a previous\
34 \ pattern, so it should be removed."
34 \ pattern, so it should be removed."
35 )
35 )
@@ -42,10 +42,10 @@ toReport source err =
42 (
42 (
43 "This pattern does not cover all possiblities:"
43 "This pattern does not cover all possiblities:"
44 ,
44 ,
45− H.stack
45+ D.stack
46 [ "Other possibilities include:"
46 [ "Other possibilities include:"
47 , unhandledPatternsToDocBlock unhandled
47 , unhandledPatternsToDocBlock unhandled
48− , H.reflow $
48+ , D.reflow $
49 "I would have to crash if I saw one of those! So rather than\
49 "I would have to crash if I saw one of those! So rather than\
50 \ pattern matching in function arguments, put a `case` in\
50 \ pattern matching in function arguments, put a `case` in\
51 \ the function body to account for all possibilities."
51 \ the function body to account for all possibilities."
@@ -58,14 +58,14 @@ toReport source err =
58 (
58 (
59 "This pattern does not cover all possible values:"
59 "This pattern does not cover all possible values:"
60 ,
60 ,
61− H.stack
61+ D.stack
62 [ "Other possibilities include:"
62 [ "Other possibilities include:"
63 , unhandledPatternsToDocBlock unhandled
63 , unhandledPatternsToDocBlock unhandled
64− , H.reflow $
64+ , D.reflow $
65 "I would have to crash if I saw one of those! You can use\
65 "I would have to crash if I saw one of those! You can use\
66 \ `let` to deconstruct values only if there is ONE possiblity.\
66 \ `let` to deconstruct values only if there is ONE possiblity.\
67 \ Switch to a `case` expression to account for all possibilities."
67 \ Switch to a `case` expression to account for all possibilities."
68− , H.toSimpleHint $
68+ , D.toSimpleHint $
69 "Are you calling a function that definitely returns values\
69 "Are you calling a function that definitely returns values\
70 \ with a very specific shape? Try making the return type of\
70 \ with a very specific shape? Try making the return type of\
71 \ that function more specific!"
71 \ that function more specific!"
@@ -78,12 +78,12 @@ toReport source err =
78 (
78 (
79 "This `case` does not have branches for all possibilities:"
79 "This `case` does not have branches for all possibilities:"
80 ,
80 ,
81− H.stack
81+ D.stack
82 [ "Missing possibilities include:"
82 [ "Missing possibilities include:"
83 , unhandledPatternsToDocBlock unhandled
83 , unhandledPatternsToDocBlock unhandled
84− , H.reflow $
84+ , D.reflow $
85 "I would have to crash if I saw one of those. Add branches for them!"
85 "I would have to crash if I saw one of those. Add branches for them!"
86− , H.link "Hint"
86+ , D.link "Hint"
87 "If you want to write the code for each branch later, use `Debug.todo` as a placeholder. Read"
87 "If you want to write the code for each branch later, use `Debug.todo` as a placeholder. Read"
88 "missing-patterns"
88 "missing-patterns"
89 "for more guidance on this workflow."
89 "for more guidance on this workflow."
@@ -95,9 +95,9 @@ toReport source err =
95-- PATTERN TO DOC
95-- PATTERN TO DOC
96
96
97
97
98−unhandledPatternsToDocBlock :: [P.Pattern] -> H.Doc
98+unhandledPatternsToDocBlock :: [P.Pattern] -> D.Doc
99unhandledPatternsToDocBlock unhandledPatterns =
99unhandledPatternsToDocBlock unhandledPatterns =
100− H.indent 4 $ H.dullyellow $ H.vcat $
100+ D.indent 4 $ D.dullyellow $ D.vcat $
101 map (patternToDoc Unambiguous) unhandledPatterns
101 map (patternToDoc Unambiguous) unhandledPatterns
102
102
103
103
@@ -108,7 +108,7 @@ data Context
108 deriving (Eq)
108 deriving (Eq)
109
109
110
110
111−patternToDoc :: Context -> P.Pattern -> H.Doc
111+patternToDoc :: Context -> P.Pattern -> D.Doc
112patternToDoc context pattern =
112patternToDoc context pattern =
113 case delist pattern [] of
113 case delist pattern [] of
114 NonList P.Anything ->
114 NonList P.Anything ->
@@ -117,13 +117,13 @@ patternToDoc context pattern =
117 NonList (P.Literal literal) ->
117 NonList (P.Literal literal) ->
118 case literal of
118 case literal of
119 P.Chr chr ->
119 P.Chr chr ->
120− H.textToDoc ("'" <> chr <> "'")
120+ D.fromText ("'" <> chr <> "'")
121
121
122 P.Str str ->
122 P.Str str ->
123− H.textToDoc ("\"" <> str <> "\"")
123+ D.fromText ("\"" <> str <> "\"")
124
124
125 P.Int int ->
125 P.Int int ->
126− H.text (show int)
126+ D.fromString (show int)
127
127
128 NonList (P.Ctor _ "#0" []) ->
128 NonList (P.Ctor _ "#0" []) ->
129 "()"
129 "()"
@@ -142,7 +142,7 @@ patternToDoc context pattern =
142 NonList (P.Ctor _ name args) ->
142 NonList (P.Ctor _ name args) ->
143 let
143 let
144 ctorDoc =
144 ctorDoc =
145− H.hsep (H.nameToDoc name : map (patternToDoc Arg) args)
145+ D.hsep (D.fromName name : map (patternToDoc Arg) args)
146 in
146 in
147 if context == Arg && length args > 0 then
147 if context == Arg && length args > 0 then
148 "(" <> ctorDoc <> ")"
148 "(" <> ctorDoc <> ")"
@@ -154,7 +154,7 @@ patternToDoc context pattern =
154
154
155 FiniteList entries ->
155 FiniteList entries ->
156 let entryDocs = map (patternToDoc Unambiguous) entries in
156 let entryDocs = map (patternToDoc Unambiguous) entries in
157− "[" <> H.hcat (List.intersperse "," entryDocs) <> "]"
157+ "[" <> D.hcat (List.intersperse "," entryDocs) <> "]"
158
158
159 Conses conses finalPattern ->
159 Conses conses finalPattern ->
160 let
160 let
compiler/src/Reporting/Error/Syntax.hs+65−65
@@ -17,10 +17,10 @@ import qualified Data.Set as Set
17import qualified Data.Text as Text
17import qualified Data.Text as Text
18
18
19import qualified Elm.Name as N
19import qualified Elm.Name as N
20+import qualified Reporting.Doc as D
20import qualified Reporting.Region as R
21import qualified Reporting.Region as R
21import qualified Reporting.Render.Code as Code
22import qualified Reporting.Render.Code as Code
22import qualified Reporting.Report as Report
23import qualified Reporting.Report as Report
23−import qualified Reporting.Helpers as H
24
24
25
25
26
26
@@ -144,7 +144,7 @@ toReport source err =
144 (
144 (
145 "This documentation comment is not followed by anything."
145 "This documentation comment is not followed by anything."
146 ,
146 ,
147− H.reflow $
147+ D.reflow $
148 "All documentation comments need to be right above the declaration they\
148 "All documentation comments need to be right above the declaration they\
149 \ describe. Maybe some code got deleted or commented out by accident? Or\
149 \ describe. Maybe some code got deleted or commented out by accident? Or\
150 \ maybe this comment is here by accident?"
150 \ maybe this comment is here by accident?"
@@ -154,12 +154,12 @@ toReport source err =
154 Report.Report "BAD PORT" region [] $
154 Report.Report "BAD PORT" region [] $
155 Report.toCodeSnippet source region Nothing
155 Report.toCodeSnippet source region Nothing
156 (
156 (
157− H.reflow $
157+ D.reflow $
158 "You are declaring port `" <> N.toString name <> "` in a normal module."
158 "You are declaring port `" <> N.toString name <> "` in a normal module."
159 ,
159 ,
160− H.stack
160+ D.stack
161 [ "It needs to be in a `port` module."
161 [ "It needs to be in a `port` module."
162− , H.link "Hint"
162+ , D.link "Hint"
163 "Ports are not a traditional FFI for calling JS functions directly. They need a different mindset! Read"
163 "Ports are not a traditional FFI for calling JS functions directly. They need a different mindset! Read"
164 "ports"
164 "ports"
165 "to learn how to use ports effectively."
165 "to learn how to use ports effectively."
@@ -170,17 +170,17 @@ toReport source err =
170 Report.Report "ANNOTATION MISMATCH" region [] $
170 Report.Report "ANNOTATION MISMATCH" region [] $
171 Report.toCodeSnippet source region Nothing
171 Report.toCodeSnippet source region Nothing
172 (
172 (
173− H.reflow $
173+ D.reflow $
174 "I see a `" <> N.toString annName
174 "I see a `" <> N.toString annName
175 <> "` annotation, but it is followed by a `"
175 <> "` annotation, but it is followed by a `"
176 <> N.toString defName <> "` definition."
176 <> N.toString defName <> "` definition."
177 ,
177 ,
178− H.fillSep
178+ D.fillSep
179 ["The","annotation","and","definition","names","must","match!"
179 ["The","annotation","and","definition","names","must","match!"
180 ,"Is","there","a","typo","between"
180 ,"Is","there","a","typo","between"
181− , H.dullyellow (H.nameToDoc annName)
181+ , D.dullyellow (D.fromName annName)
182 ,"and"
182 ,"and"
183− , H.dullyellow (H.nameToDoc defName) <> "?"
183+ , D.dullyellow (D.fromName defName) <> "?"
184 ]
184 ]
185 )
185 )
186
186
@@ -188,12 +188,12 @@ toReport source err =
188 Report.Report "MISSING DEFINITION" region [] $
188 Report.Report "MISSING DEFINITION" region [] $
189 Report.toCodeSnippet source region Nothing
189 Report.toCodeSnippet source region Nothing
190 (
190 (
191− H.reflow $
191+ D.reflow $
192 "There is a type annotation for `" <> N.toString name
192 "There is a type annotation for `" <> N.toString name
193 <> "` but there is no corresponding definition!"
193 <> "` but there is no corresponding definition!"
194 ,
194 ,
195 "Directly below the type annotation, put a definition like:\n\n"
195 "Directly below the type annotation, put a definition like:\n\n"
196− <> " " <> H.nameToDoc name <> " = 42"
196+ <> " " <> D.fromName name <> " = 42"
197 )
197 )
198
198
199 Parse region subRegion problem ->
199 Parse region subRegion problem ->
@@ -206,7 +206,7 @@ toReport source err =
206-- PARSE ERROR TO DOCS
206-- PARSE ERROR TO DOCS
207
207
208
208
209−problemToDocs :: Problem -> (H.Doc, H.Doc)
209+problemToDocs :: Problem -> (D.Doc, D.Doc)
210problemToDocs problem =
210problemToDocs problem =
211 case problem of
211 case problem of
212 Tab ->
212 Tab ->
@@ -220,11 +220,11 @@ problemToDocs problem =
220 (
220 (
221 "I got to the end of the file while parsing a multi-line comment."
221 "I got to the end of the file while parsing a multi-line comment."
222 ,
222 ,
223− H.stack
223+ D.stack
224− [ H.reflow $
224+ [ D.reflow $
225 "Multi-line comments look like {- comment -}, and it looks like\
225 "Multi-line comments look like {- comment -}, and it looks like\
226 \ you are missing the closing marker."
226 \ you are missing the closing marker."
227− , H.toSimpleHint $
227+ , D.toSimpleHint $
228 "Nested multi-line comments like {- this {- and this -} -} are allowed.\
228 "Nested multi-line comments like {- this {- and this -} -} are allowed.\
229 \ The opening and closing markers must be balanced though, just\
229 \ The opening and closing markers must be balanced though, just\
230 \ like parentheses in normal code. Maybe that is the problem?"
230 \ like parentheses in normal code. Maybe that is the problem?"
@@ -235,7 +235,7 @@ problemToDocs problem =
235 (
235 (
236 "I got to the end of the file while parsing a GLSL block."
236 "I got to the end of the file while parsing a GLSL block."
237 ,
237 ,
238− H.reflow $
238+ D.reflow $
239 "A shader should be defined in a block like this: [glsl| ... |]"
239 "A shader should be defined in a block like this: [glsl| ... |]"
240 )
240 )
241
241
@@ -243,7 +243,7 @@ problemToDocs problem =
243 (
243 (
244 "I got to the end of the file while parsing a string."
244 "I got to the end of the file while parsing a string."
245 ,
245 ,
246− H.reflow $
246+ D.reflow $
247 "Strings look like \"this\" with double quotes on each end.\
247 "Strings look like \"this\" with double quotes on each end.\
248 \ Is the closing double quote missing in your code?"
248 \ Is the closing double quote missing in your code?"
249 )
249 )
@@ -252,7 +252,7 @@ problemToDocs problem =
252 (
252 (
253 "I got to the end of the file while parsing a multi-line string."
253 "I got to the end of the file while parsing a multi-line string."
254 ,
254 ,
255− H.reflow $
255+ D.reflow $
256 "Multi-line strings look like \"\"\"this\"\"\" with three double quotes on each\
256 "Multi-line strings look like \"\"\"this\"\"\" with three double quotes on each\
257 \ end. Is the closing triple quote missing in your code?"
257 \ end. Is the closing triple quote missing in your code?"
258 )
258 )
@@ -261,7 +261,7 @@ problemToDocs problem =
261 (
261 (
262 "I got to the end of the file while parsing a character."
262 "I got to the end of the file while parsing a character."
263 ,
263 ,
264− H.reflow $
264+ D.reflow $
265 "Characters look like 'c' with single quotes on each end.\
265 "Characters look like 'c' with single quotes on each end.\
266 \ Is the closing single quote missing in your code?"
266 \ Is the closing single quote missing in your code?"
267 )
267 )
@@ -270,10 +270,10 @@ problemToDocs problem =
270 (
270 (
271 "This string is missing the closing quote."
271 "This string is missing the closing quote."
272 ,
272 ,
273− H.stack
273+ D.stack
274− [ H.reflow $
274+ [ D.reflow $
275 "Elm strings like \"this\" cannot contain newlines."
275 "Elm strings like \"this\" cannot contain newlines."
276− , H.toSimpleHint $
276+ , D.toSimpleHint $
277 "For strings that CAN contain newlines, say \"\"\"this\"\"\" for Elm’s\
277 "For strings that CAN contain newlines, say \"\"\"this\"\"\" for Elm’s\
278 \ multi-line string syntax. It allows unescaped newlines and double quotes."
278 \ multi-line string syntax. It allows unescaped newlines and double quotes."
279 ]
279 ]
@@ -292,10 +292,10 @@ problemToDocs problem =
292 UnknownEscape ->
292 UnknownEscape ->
293 (
293 (
294 "Backslashes always start escaped characters, but I do not recognize this one:"
294 "Backslashes always start escaped characters, but I do not recognize this one:"
295− , H.stack
295+ , D.stack
296 [ "Maybe there is some typo?"
296 [ "Maybe there is some typo?"
297− , H.toSimpleHint "Valid escape characters include:"
297+ , D.toSimpleHint "Valid escape characters include:"
298− , H.indent 4 $ H.vcat $
298+ , D.indent 4 $ D.vcat $
299 [ "\\n"
299 [ "\\n"
300 , "\\r"
300 , "\\r"
301 , "\\t"
301 , "\\t"
@@ -304,7 +304,7 @@ problemToDocs problem =
304 , "\\\\"
304 , "\\\\"
305 , "\\u{03BB}"
305 , "\\u{03BB}"
306 ]
306 ]
307− , H.reflow $
307+ , D.reflow $
308 "The last one lets encode ANY character by its Unicode code\
308 "The last one lets encode ANY character by its Unicode code\
309 \ point, so use that for anything outside the ordinary six."
309 \ point, so use that for anything outside the ordinary six."
310 ]
310 ]
@@ -314,15 +314,15 @@ problemToDocs problem =
314 (
314 (
315 "I ran into an invalid Unicode escape character:"
315 "I ran into an invalid Unicode escape character:"
316 ,
316 ,
317− H.stack
317+ D.stack
318 [ "Here are some examples of valid Unicode escape characters:"
318 [ "Here are some examples of valid Unicode escape characters:"
319− , H.indent 4 $ H.vcat $
319+ , D.indent 4 $ D.vcat $
320 [ "\\u{0041}"
320 [ "\\u{0041}"
321 , "\\u{03BB}"
321 , "\\u{03BB}"
322 , "\\u{6728}"
322 , "\\u{6728}"
323 , "\\u{1F60A}"
323 , "\\u{1F60A}"
324 ]
324 ]
325− , H.reflow $
325+ , D.reflow $
326 "Notice that the code point is always surrounded by curly\
326 "Notice that the code point is always surrounded by curly\
327 \ braces. They are required!"
327 \ braces. They are required!"
328 ]
328 ]
@@ -342,18 +342,18 @@ problemToDocs problem =
342 ,
342 ,
343 let
343 let
344 goodCode = replicate (4 - numDigits) '0' ++ badCode
344 goodCode = replicate (4 - numDigits) '0' ++ badCode
345− escape = "\\u{" <> H.text goodCode <> "}"
345+ escape = "\\u{" <> D.fromString goodCode <> "}"
346 in
346 in
347− H.hsep [ "Try", H.dullyellow escape, "instead?" ]
347+ D.hsep [ "Try", D.dullyellow escape, "instead?" ]
348 )
348 )
349
349
350 else
350 else
351 (
351 (
352 "This Unicode code point has too many digits:"
352 "This Unicode code point has too many digits:"
353 ,
353 ,
354− H.fillSep
354+ D.fillSep
355 ["Valid","code","points","are","between"
355 ["Valid","code","points","are","between"
356− , H.dullyellow "\\u{0000}", "and", H.dullyellow "\\u{10FFFF}"
356+ , D.dullyellow "\\u{0000}", "and", D.dullyellow "\\u{10FFFF}"
357 ,"so","it","must","have","between","four","and","six","digits."
357 ,"so","it","must","have","between","four","and","six","digits."
358 ]
358 ]
359 )
359 )
@@ -362,12 +362,12 @@ problemToDocs problem =
362 (
362 (
363 "Ran into a bad use of single quotes."
363 "Ran into a bad use of single quotes."
364 ,
364 ,
365− H.stack
365+ D.stack
366− [ H.reflow $
366+ [ D.reflow $
367 "If you want to create a string, switch to double quotes:"
367 "If you want to create a string, switch to double quotes:"
368− , H.indent 4 $
368+ , D.indent 4 $
369− H.dullyellow "'this'" <> " => " <> H.green "\"this\""
369+ D.dullyellow "'this'" <> " => " <> D.green "\"this\""
370− , H.toSimpleHint $
370+ , D.toSimpleHint $
371 "Unlike JavaScript, Elm distinguishes between strings like \"hello\"\
371 "Unlike JavaScript, Elm distinguishes between strings like \"hello\"\
372 \ and individual characters like 'A' and '3'. If you really do want\
372 \ and individual characters like 'A' and '3'. If you really do want\
373 \ a character though, something went wrong and I did not find the\
373 \ a character though, something went wrong and I did not find the\
@@ -381,16 +381,16 @@ problemToDocs problem =
381 ,
381 ,
382 let
382 let
383 number =
383 number =
384− H.text (show numberBeforeDot)
384+ D.fromString (show numberBeforeDot)
385 in
385 in
386− "Saying " <> H.green number <> " or " <> H.green (number <> ".0") <> " will work though!"
386+ "Saying " <> D.green number <> " or " <> D.green (number <> ".0") <> " will work though!"
387 )
387 )
388
388
389 BadNumberEnd ->
389 BadNumberEnd ->
390 (
390 (
391 "Numbers cannot have letters or underscores in them."
391 "Numbers cannot have letters or underscores in them."
392 ,
392 ,
393− H.reflow $
393+ D.reflow $
394 "Maybe a space is missing between a number and a variable?"
394 "Maybe a space is missing between a number and a variable?"
395 )
395 )
396
396
@@ -398,7 +398,7 @@ problemToDocs problem =
398 (
398 (
399 "If you put the letter E in a number, it should followed by more digits."
399 "If you put the letter E in a number, it should followed by more digits."
400 ,
400 ,
401− H.reflow $
401+ D.reflow $
402 "If you want to say 1000, you can also say 1e3.\
402 "If you want to say 1000, you can also say 1e3.\
403 \ You cannot just end it with an E though!"
403 \ You cannot just end it with an E though!"
404 )
404 )
@@ -407,7 +407,7 @@ problemToDocs problem =
407 (
407 (
408 "I see the start of a hex number, but not the end."
408 "I see the start of a hex number, but not the end."
409 ,
409 ,
410− H.reflow $
410+ D.reflow $
411 "A hex number looks like 0x123ABC, where the 0x is followed by hexidecimal\
411 "A hex number looks like 0x123ABC, where the 0x is followed by hexidecimal\
412 \ digits. Valid hexidecimal digits include: 0123456789abcdefABCDEF"
412 \ digits. Valid hexidecimal digits include: 0123456789abcdefABCDEF"
413 )
413 )
@@ -416,7 +416,7 @@ problemToDocs problem =
416 (
416 (
417 "Normal numbers cannot start with zeros. Take the zeros off the front."
417 "Normal numbers cannot start with zeros. Take the zeros off the front."
418 ,
418 ,
419− H.reflow $
419+ D.reflow $
420 "Only numbers like 0x0040 or 0.25 can start with a zero."
420 "Only numbers like 0x0040 or 0.25 can start with a zero."
421 )
421 )
422
422
@@ -424,7 +424,7 @@ problemToDocs problem =
424 (
424 (
425 "I cannot pattern match with floating point numbers:"
425 "I cannot pattern match with floating point numbers:"
426 ,
426 ,
427− H.reflow $
427+ D.reflow $
428 "Equality on floats can be unreliable, so you usually want to check that they\
428 "Equality on floats can be unreliable, so you usually want to check that they\
429 \ are nearby with some sort of (abs (actual - expected) < 0.001) check."
429 \ are nearby with some sort of (abs (actual - expected) < 0.001) check."
430 )
430 )
@@ -433,14 +433,14 @@ problemToDocs problem =
433 (
433 (
434 "I ran into a problem while parsing this GLSL block."
434 "I ran into a problem while parsing this GLSL block."
435 ,
435 ,
436− H.reflow (Text.unpack msg)
436+ D.reflow (Text.unpack msg)
437 )
437 )
438
438
439 BadUnderscore _ ->
439 BadUnderscore _ ->
440 (
440 (
441 "A variable name cannot start with an underscore:"
441 "A variable name cannot start with an underscore:"
442 ,
442 ,
443− H.reflow $
443+ D.reflow $
444 "You can (1) use a wildcard like _ to ignore the value or you can (2) use\
444 "You can (1) use a wildcard like _ to ignore the value or you can (2) use\
445 \ a name that starts with a letter to access the value later. Pick one!"
445 \ a name that starts with a letter to access the value later. Pick one!"
446 )
446 )
@@ -454,7 +454,7 @@ problemToDocs problem =
454
454
455 Equals ->
455 Equals ->
456 (
456 (
457− H.reflow $
457+ D.reflow $
458 "I was not expecting this equals sign"
458 "I was not expecting this equals sign"
459 <> contextToString " here" " while parsing " stack <> "."
459 <> contextToString " here" " while parsing " stack <> "."
460 ,
460 ,
@@ -466,7 +466,7 @@ problemToDocs problem =
466 (
466 (
467 "I ran into a stray arrow while parsing this `case` expression."
467 "I ran into a stray arrow while parsing this `case` expression."
468 ,
468 ,
469− H.reflow $
469+ D.reflow $
470 "All branches in a `case` must be indented the exact\
470 "All branches in a `case` must be indented the exact\
471 \ same amount, so the patterns are vertically\
471 \ same amount, so the patterns are vertically\
472 \ aligned. Maybe this branch is indented too much?"
472 \ aligned. Maybe this branch is indented too much?"
@@ -486,7 +486,7 @@ problemToDocs problem =
486 (
486 (
487 "I was not expecting this dot."
487 "I was not expecting this dot."
488 ,
488 ,
489− H.reflow $
489+ D.reflow $
490 "Dots are for record access and decimal points, so\
490 "Dots are for record access and decimal points, so\
491 \ they cannot float around on their own. Maybe\
491 \ they cannot float around on their own. Maybe\
492 \ there is some extra whitespace?"
492 \ there is some extra whitespace?"
@@ -494,27 +494,27 @@ problemToDocs problem =
494
494
495 Theories stack allTheories ->
495 Theories stack allTheories ->
496 (
496 (
497− H.reflow $
497+ D.reflow $
498 "Something went wrong while parsing " <> contextToString "your code" "" stack <> "."
498 "Something went wrong while parsing " <> contextToString "your code" "" stack <> "."
499 ,
499 ,
500 case Set.toList (Set.fromList allTheories) of
500 case Set.toList (Set.fromList allTheories) of
501 [] ->
501 [] ->
502− H.stack
502+ D.stack
503− [ H.reflow $
503+ [ D.reflow $
504 "I do not have any suggestions though!"
504 "I do not have any suggestions though!"
505− , H.reflow $
505+ , D.reflow $
506 "Can you get it down to a <http://sscce.org> and share it at\
506 "Can you get it down to a <http://sscce.org> and share it at\
507 \ <https://github.com/elm-lang/error-message-catalog/issues>?\
507 \ <https://github.com/elm-lang/error-message-catalog/issues>?\
508 \ That way we can figure out how to give better advice!"
508 \ That way we can figure out how to give better advice!"
509 ]
509 ]
510
510
511 [theory] ->
511 [theory] ->
512− H.reflow $
512+ D.reflow $
513 "I was expecting to see "
513 "I was expecting to see "
514 <> addPeriod (theoryToString stack theory)
514 <> addPeriod (theoryToString stack theory)
515
515
516 theories ->
516 theories ->
517− H.vcat $
517+ D.vcat $
518 [ "I was expecting:"
518 [ "I was expecting:"
519 , ""
519 , ""
520 ]
520 ]
@@ -526,33 +526,33 @@ problemToDocs problem =
526-- BAD OP HELPERS
526-- BAD OP HELPERS
527
527
528
528
529−badOp :: ContextStack -> String -> String -> String -> String -> ( H.Doc, H.Doc )
529+badOp :: ContextStack -> String -> String -> String -> String -> ( D.Doc, D.Doc )
530badOp stack article opName setting hint =
530badOp stack article opName setting hint =
531 (
531 (
532− H.reflow $
532+ D.reflow $
533 "I was not expecting this " <> opName
533 "I was not expecting this " <> opName
534 <> contextToString " here" " while parsing " stack <> "."
534 <> contextToString " here" " while parsing " stack <> "."
535 ,
535 ,
536− H.reflow $
536+ D.reflow $
537 article <> " " <> opName <> " should only appear in "
537 article <> " " <> opName <> " should only appear in "
538 <> setting <> ". " <> hint
538 <> setting <> ". " <> hint
539 )
539 )
540
540
541
541
542−toBadEqualsHint :: ContextStack -> H.Doc
542+toBadEqualsHint :: ContextStack -> D.Doc
543toBadEqualsHint stack =
543toBadEqualsHint stack =
544 case stack of
544 case stack of
545 [] ->
545 [] ->
546− H.reflow $
546+ D.reflow $
547 "Maybe you want == instead? Or maybe something is indented too much?"
547 "Maybe you want == instead? Or maybe something is indented too much?"
548
548
549 (ExprRecord, _) : _ ->
549 (ExprRecord, _) : _ ->
550− H.reflow $
550+ D.reflow $
551 "Records look like { x = 3, y = 4 } with the equals sign right\
551 "Records look like { x = 3, y = 4 } with the equals sign right\
552 \ after the field name. Maybe you forgot a comma?"
552 \ after the field name. Maybe you forgot a comma?"
553
553
554 (Definition _, _) : rest ->
554 (Definition _, _) : rest ->
555− H.reflow $
555+ D.reflow $
556 "Maybe this is supposed to be a separate definition? If so, it\
556 "Maybe this is supposed to be a separate definition? If so, it\
557 \ is indented too far. "
557 \ is indented too far. "
558 <>
558 <>
@@ -634,9 +634,9 @@ getAnchor stack =
634-- THEORY HELPERS
634-- THEORY HELPERS
635
635
636
636
637−bullet :: String -> H.Doc
637+bullet :: String -> D.Doc
638bullet point =
638bullet point =
639− H.hang 4 (" - " <> H.fillSep (map H.text (words point)))
639+ D.hang 4 (" - " <> D.fillSep (map D.fromString (words point)))
640
640
641
641
642addPeriod :: String -> String
642addPeriod :: String -> String
compiler/src/Reporting/Error/Type.hs+251−251
@@ -24,7 +24,7 @@ import Data.Monoid ((<>))
24
24
25import qualified Data.Index as Index
25import qualified Data.Index as Index
26import qualified Elm.Name as N
26import qualified Elm.Name as N
27−import qualified Reporting.Helpers as H
27+import qualified Reporting.Doc as D
28import qualified Reporting.Region as R
28import qualified Reporting.Region as R
29import qualified Reporting.Render.Code as Code
29import qualified Reporting.Render.Code as Code
30import qualified Reporting.Render.Type as RT
30import qualified Reporting.Render.Type as RT
@@ -202,15 +202,15 @@ toPatternReport source localizer patternRegion category tipe expected =
202 case context of
202 case context of
203 PTypedArg name index ->
203 PTypedArg name index ->
204 (
204 (
205− H.reflow $
205+ D.reflow $
206− "The " <> H.ordinalize (Index.toHuman index) <> " argument to `" <> N.toString name <> "` is weird."
206+ "The " <> D.ordinalize (Index.toHuman index) <> " argument to `" <> N.toString name <> "` is weird."
207 ,
207 ,
208 patternTypeComparison localizer tipe expectedType
208 patternTypeComparison localizer tipe expectedType
209 (
209 (
210 toPatternDescription category $
210 toPatternDescription category $
211 "The argument is a pattern that matches"
211 "The argument is a pattern that matches"
212 ,
212 ,
213− "But the type annotation on `" <> N.toString name <> "` says the " <> H.ordinalize (Index.toHuman index) <> " argument should be:"
213+ "But the type annotation on `" <> N.toString name <> "` says the " <> D.ordinalize (Index.toHuman index) <> " argument should be:"
214 ,
214 ,
215 []
215 []
216 )
216 )
@@ -219,7 +219,7 @@ toPatternReport source localizer patternRegion category tipe expected =
219 PCaseMatch index ->
219 PCaseMatch index ->
220 if index == Index.first then
220 if index == Index.first then
221 (
221 (
222− H.reflow $
222+ D.reflow $
223 "The 1st pattern in this `case` causing a mismatch:"
223 "The 1st pattern in this `case` causing a mismatch:"
224 ,
224 ,
225 patternTypeComparison localizer tipe expectedType
225 patternTypeComparison localizer tipe expectedType
@@ -228,20 +228,20 @@ toPatternReport source localizer patternRegion category tipe expected =
228 ,
228 ,
229 "But it is supposed to match an expression of type:"
229 "But it is supposed to match an expression of type:"
230 ,
230 ,
231− [ H.reflow $
231+ [ D.reflow $
232 "Is the pattern the problem? Or is it the expression you are trying to match on?"
232 "Is the pattern the problem? Or is it the expression you are trying to match on?"
233 ]
233 ]
234 )
234 )
235 )
235 )
236 else
236 else
237 (
237 (
238− H.reflow $
238+ D.reflow $
239− "The " <> H.ordinalize (Index.toHuman index) <> " pattern in this `case` does not match the previous ones."
239+ "The " <> D.ordinalize (Index.toHuman index) <> " pattern in this `case` does not match the previous ones."
240 ,
240 ,
241 patternTypeComparison localizer tipe expectedType
241 patternTypeComparison localizer tipe expectedType
242 (
242 (
243 toPatternDescription category $
243 toPatternDescription category $
244− "The " <> H.ordinalize (Index.toHuman index) <> " pattern is trying to match"
244+ "The " <> D.ordinalize (Index.toHuman index) <> " pattern is trying to match"
245 ,
245 ,
246 "But all the previous patterns match values of type:"
246 "But all the previous patterns match values of type:"
247 ,
247 ,
@@ -251,14 +251,14 @@ toPatternReport source localizer patternRegion category tipe expected =
251
251
252 PCtorArg name index ->
252 PCtorArg name index ->
253 (
253 (
254− H.reflow $
254+ D.reflow $
255− "The " <> H.ordinalize (Index.toHuman index) <> " argument to `" <> N.toString name <> "` is weird."
255+ "The " <> D.ordinalize (Index.toHuman index) <> " argument to `" <> N.toString name <> "` is weird."
256 ,
256 ,
257 patternTypeComparison localizer tipe expectedType
257 patternTypeComparison localizer tipe expectedType
258 (
258 (
259 toPatternDescription category "It is trying to match"
259 toPatternDescription category "It is trying to match"
260 ,
260 ,
261− "But `" <> N.toString name <> "` needs its " <> H.ordinalize (Index.toHuman index) <> " argument to be:"
261+ "But `" <> N.toString name <> "` needs its " <> D.ordinalize (Index.toHuman index) <> " argument to be:"
262 ,
262 ,
263 []
263 []
264 )
264 )
@@ -266,17 +266,17 @@ toPatternReport source localizer patternRegion category tipe expected =
266
266
267 PListEntry index ->
267 PListEntry index ->
268 (
268 (
269− H.reflow $
269+ D.reflow $
270− "The " <> H.ordinalize (Index.toHuman index) <> " pattern in this list does not match all the previous ones:"
270+ "The " <> D.ordinalize (Index.toHuman index) <> " pattern in this list does not match all the previous ones:"
271 ,
271 ,
272 patternTypeComparison localizer tipe expectedType
272 patternTypeComparison localizer tipe expectedType
273 (
273 (
274 toPatternDescription category $
274 toPatternDescription category $
275− "The " <> H.ordinalize (Index.toHuman index) <> " pattern is trying to match"
275+ "The " <> D.ordinalize (Index.toHuman index) <> " pattern is trying to match"
276 ,
276 ,
277 "But all the previous patterns in the list are:"
277 "But all the previous patterns in the list are:"
278 ,
278 ,
279− [ H.toSimpleHint $
279+ [ D.toSimpleHint $
280 "Everything in the list needs to be the same type of value.\
280 "Everything in the list needs to be the same type of value.\
281 \ This way you never run into unexpected values partway through.\
281 \ This way you never run into unexpected values partway through.\
282 \ To mix different types in a single list, create a \"union type\" as\
282 \ To mix different types in a single list, create a \"union type\" as\
@@ -287,7 +287,7 @@ toPatternReport source localizer patternRegion category tipe expected =
287
287
288 PTail ->
288 PTail ->
289 (
289 (
290− H.reflow $
290+ D.reflow $
291 "The pattern after (::) is causing issues."
291 "The pattern after (::) is causing issues."
292 ,
292 ,
293 patternTypeComparison localizer tipe expectedType
293 patternTypeComparison localizer tipe expectedType
@@ -306,17 +306,17 @@ toPatternReport source localizer patternRegion category tipe expected =
306-- PATTERN HELPERS
306-- PATTERN HELPERS
307
307
308
308
309−patternTypeComparison :: T.Localizer -> T.Type -> T.Type -> ( String, String, [H.Doc] ) -> H.Doc
309+patternTypeComparison :: T.Localizer -> T.Type -> T.Type -> ( String, String, [D.Doc] ) -> D.Doc
310patternTypeComparison localizer actual expected ( iAmSeeing, insteadOf, contextHints ) =
310patternTypeComparison localizer actual expected ( iAmSeeing, insteadOf, contextHints ) =
311 let
311 let
312 (actualDoc, expectedDoc, problems) =
312 (actualDoc, expectedDoc, problems) =
313 T.toDiffDocs localizer actual expected
313 T.toDiffDocs localizer actual expected
314 in
314 in
315− H.stack $
315+ D.stack $
316− [ H.reflow iAmSeeing
316+ [ D.reflow iAmSeeing
317− , H.indent 4 actualDoc
317+ , D.indent 4 actualDoc
318− , H.reflow insteadOf
318+ , D.reflow insteadOf
319− , H.indent 4 expectedDoc
319+ , D.indent 4 expectedDoc
320 ]
320 ]
321 ++ problemsToHint problems
321 ++ problemsToHint problems
322 ++ contextHints
322 ++ contextHints
@@ -340,31 +340,31 @@ toPatternDescription category iAmTryingToMatch =
340-- EXPR HELPERS
340-- EXPR HELPERS
341
341
342
342
343−typeComparison :: T.Localizer -> T.Type -> T.Type -> ( String, String, [H.Doc] ) -> H.Doc
343+typeComparison :: T.Localizer -> T.Type -> T.Type -> ( String, String, [D.Doc] ) -> D.Doc
344typeComparison localizer actual expected ( iAmSeeing, insteadOf, contextHints ) =
344typeComparison localizer actual expected ( iAmSeeing, insteadOf, contextHints ) =
345 let
345 let
346 (actualDoc, expectedDoc, problems) =
346 (actualDoc, expectedDoc, problems) =
347 T.toDiffDocs localizer actual expected
347 T.toDiffDocs localizer actual expected
348 in
348 in
349− H.stack $
349+ D.stack $
350− [ H.reflow iAmSeeing
350+ [ D.reflow iAmSeeing
351− , H.indent 4 actualDoc
351+ , D.indent 4 actualDoc
352− , H.reflow insteadOf
352+ , D.reflow insteadOf
353− , H.indent 4 expectedDoc
353+ , D.indent 4 expectedDoc
354 ]
354 ]
355 ++ problemsToHint problems
355 ++ problemsToHint problems
356 ++ contextHints
356 ++ contextHints
357
357
358
358
359−loneType :: T.Localizer -> T.Type -> T.Type -> ( H.Doc, [H.Doc] ) -> H.Doc
359+loneType :: T.Localizer -> T.Type -> T.Type -> ( D.Doc, [D.Doc] ) -> D.Doc
360loneType localizer actual expected ( iAmSeeing, furtherDetails ) =
360loneType localizer actual expected ( iAmSeeing, furtherDetails ) =
361 let
361 let
362 (actualDoc, _, problems) =
362 (actualDoc, _, problems) =
363 T.toDiffDocs localizer actual expected
363 T.toDiffDocs localizer actual expected
364 in
364 in
365− H.stack $
365+ D.stack $
366 [ iAmSeeing
366 [ iAmSeeing
367− , H.indent 4 actualDoc
367+ , D.indent 4 actualDoc
368 ]
368 ]
369 ++ furtherDetails
369 ++ furtherDetails
370 ++ problemsToHint problems
370 ++ problemsToHint problems
@@ -398,7 +398,7 @@ toDescription category thatThingIs =
398 OpName _ -> thatThingIs <> ":"
398 OpName _ -> thatThingIs <> ":"
399
399
400
400
401−problemsToHint :: [T.Problem] -> [H.Doc]
401+problemsToHint :: [T.Problem] -> [D.Doc]
402problemsToHint problems =
402problemsToHint problems =
403 case problems of
403 case problems of
404 [] ->
404 [] ->
@@ -408,63 +408,63 @@ problemsToHint problems =
408 problemToHint problem
408 problemToHint problem
409
409
410
410
411−problemToHint :: T.Problem -> [H.Doc]
411+problemToHint :: T.Problem -> [D.Doc]
412problemToHint problem =
412problemToHint problem =
413 case problem of
413 case problem of
414 T.FieldMismatch _ _ -> [] -- TODO do a better job?
414 T.FieldMismatch _ _ -> [] -- TODO do a better job?
415
415
416 T.IntFloat ->
416 T.IntFloat ->
417− [ H.fancyLink "Note" ["Read"] "implicit-casts"
417+ [ D.fancyLink "Note" ["Read"] "implicit-casts"
418 ["to","learn","why","Elm","does","not","implicitly","convert"
418 ["to","learn","why","Elm","does","not","implicitly","convert"
419− ,"Ints","to","Floats.","Use",H.green "toFloat","and"
419+ ,"Ints","to","Floats.","Use",D.green "toFloat","and"
420− ,H.green "round","to","do","explicit","conversions."
420+ ,D.green "round","to","do","explicit","conversions."
421 ]
421 ]
422 ]
422 ]
423
423
424 T.StringFromInt ->
424 T.StringFromInt ->
425− [ H.toFancyHint
425+ [ D.toFancyHint
426 ["Want","to","convert","an","Int","into","a","String?"
426 ["Want","to","convert","an","Int","into","a","String?"
427− ,"Use","the",H.green "String.fromInt","function!"
427+ ,"Use","the",D.green "String.fromInt","function!"
428 ]
428 ]
429 ]
429 ]
430
430
431 T.StringFromFloat ->
431 T.StringFromFloat ->
432− [ H.toFancyHint
432+ [ D.toFancyHint
433 ["Want","to","convert","a","Float","into","a","String?"
433 ["Want","to","convert","a","Float","into","a","String?"
434− ,"Use","the",H.green "String.fromFloat","function!"
434+ ,"Use","the",D.green "String.fromFloat","function!"
435 ]
435 ]
436 ]
436 ]
437
437
438 T.StringToInt ->
438 T.StringToInt ->
439− [ H.toFancyHint
439+ [ D.toFancyHint
440 ["Want","to","convert","a","String","into","an","Int?"
440 ["Want","to","convert","a","String","into","an","Int?"
441− ,"Use","the",H.green "String.toInt","function!"
441+ ,"Use","the",D.green "String.toInt","function!"
442 ]
442 ]
443 ]
443 ]
444
444
445 T.StringToFloat ->
445 T.StringToFloat ->
446− [ H.toFancyHint
446+ [ D.toFancyHint
447 ["Want","to","convert","a","String","into","a","Float?"
447 ["Want","to","convert","a","String","into","a","Float?"
448− ,"Use","the",H.green "String.toFloat","function!"
448+ ,"Use","the",D.green "String.toFloat","function!"
449 ]
449 ]
450 ]
450 ]
451
451
452 T.AnythingToBool ->
452 T.AnythingToBool ->
453− [ H.toSimpleHint $
453+ [ D.toSimpleHint $
454 "Elm does not have “truthiness” such that ints and strings and lists\
454 "Elm does not have “truthiness” such that ints and strings and lists\
455 \ are automatically converted to booleans. Do that conversion explicitly!"
455 \ are automatically converted to booleans. Do that conversion explicitly!"
456 ]
456 ]
457
457
458 T.AnythingFromMaybe ->
458 T.AnythingFromMaybe ->
459− [ H.toFancyHint
459+ [ D.toFancyHint
460− ["Use",H.green "Maybe.withDefault","to","handle","possible","errors."
460+ ["Use",D.green "Maybe.withDefault","to","handle","possible","errors."
461 ,"Longer","term,","it","is","usually","better","to","write","out","the"
461 ,"Longer","term,","it","is","usually","better","to","write","out","the"
462 ,"full","`case`","though!"
462 ,"full","`case`","though!"
463 ]
463 ]
464 ]
464 ]
465
465
466 T.AnythingToList ->
466 T.AnythingToList ->
467− [ H.toSimpleHint "Did you forget to add [] around it?"
467+ [ D.toSimpleHint "Did you forget to add [] around it?"
468 ]
468 ]
469
469
470 T.MissingArgs _ -> []
470 T.MissingArgs _ -> []
@@ -520,25 +520,25 @@ problemToHint problem =
520-- BAD RIGID HINTS
520-- BAD RIGID HINTS
521
521
522
522
523−badRigidVar :: N.Name -> String -> [H.Doc]
523+badRigidVar :: N.Name -> String -> [D.Doc]
524badRigidVar name aThing =
524badRigidVar name aThing =
525− [ H.toSimpleHint $
525+ [ D.toSimpleHint $
526 "Your type annotation uses type variable `" ++ N.toString name ++
526 "Your type annotation uses type variable `" ++ N.toString name ++
527 "` which means ANY type of value can flow through, but your code is saying it specifically wants "
527 "` which means ANY type of value can flow through, but your code is saying it specifically wants "
528 ++ aThing ++ ". Maybe change your type annotation to\
528 ++ aThing ++ ". Maybe change your type annotation to\
529 \ be more specific? Maybe change the code to be more general?"
529 \ be more specific? Maybe change the code to be more general?"
530− , H.reflowLink "Read" "type-annotations" "for more advice!"
530+ , D.reflowLink "Read" "type-annotations" "for more advice!"
531 ]
531 ]
532
532
533
533
534−badDoubleRigid :: N.Name -> N.Name -> [H.Doc]
534+badDoubleRigid :: N.Name -> N.Name -> [D.Doc]
535badDoubleRigid x y =
535badDoubleRigid x y =
536− [ H.toSimpleHint $
536+ [ D.toSimpleHint $
537 "Your type annotation uses `" ++ N.toString x ++ "` and `" ++ N.toString y ++
537 "Your type annotation uses `" ++ N.toString x ++ "` and `" ++ N.toString y ++
538 "` as separate type variables. Your code seems to be saying they are the\
538 "` as separate type variables. Your code seems to be saying they are the\
539 \ same though! Maybe they should be the same in your type annotation?\
539 \ same though! Maybe they should be the same in your type annotation?\
540 \ Maybe your code uses them in a weird way?"
540 \ Maybe your code uses them in a weird way?"
541− , H.reflowLink "Read" "type-annotations" "for more advice!"
541+ , D.reflowLink "Read" "type-annotations" "for more advice!"
542 ]
542 ]
543
543
544
544
@@ -555,47 +555,47 @@ toASuperThing super =
555-- BAD SUPER HINTS
555-- BAD SUPER HINTS
556
556
557
557
558−badFlexSuper :: T.Super -> T.Type -> [H.Doc]
558+badFlexSuper :: T.Super -> T.Type -> [D.Doc]
559badFlexSuper super tipe =
559badFlexSuper super tipe =
560 case super of
560 case super of
561 T.Comparable ->
561 T.Comparable ->
562− [ H.toSimpleHint "Only ints, floats, chars, strings, lists, and tuples are comparable."
562+ [ D.toSimpleHint "Only ints, floats, chars, strings, lists, and tuples are comparable."
563 ]
563 ]
564
564
565 T.Appendable ->
565 T.Appendable ->
566 case tipe of
566 case tipe of
567 T.Type home name _ | T.isInt home name ->
567 T.Type home name _ | T.isInt home name ->
568− [ H.toFancyHint ["Try","using",H.green"String.fromInt","to","convert","it","to","a","string?"]
568+ [ D.toFancyHint ["Try","using",D.green"String.fromInt","to","convert","it","to","a","string?"]
569 ]
569 ]
570
570
571 T.Type home name _ | T.isFloat home name ->
571 T.Type home name _ | T.isFloat home name ->
572− [ H.toFancyHint ["Try","using",H.green"String.fromFloat","to","convert","it","to","a","string?"]
572+ [ D.toFancyHint ["Try","using",D.green"String.fromFloat","to","convert","it","to","a","string?"]
573 ]
573 ]
574
574
575 T.FlexSuper T.Number _ ->
575 T.FlexSuper T.Number _ ->
576− [ H.toFancyHint ["Try","using",H.green"String.fromInt","to","convert","it","to","a","string?"]
576+ [ D.toFancyHint ["Try","using",D.green"String.fromInt","to","convert","it","to","a","string?"]
577 ]
577 ]
578
578
579 _ ->
579 _ ->
580− [ H.toFancyHint ["Only","strings","and","lists","are","appendable.","Put","it","in",H.green "[]","to","make","it","a","list?"]
580+ [ D.toFancyHint ["Only","strings","and","lists","are","appendable.","Put","it","in",D.green "[]","to","make","it","a","list?"]
581 ]
581 ]
582
582
583 T.CompAppend ->
583 T.CompAppend ->
584− [ H.toSimpleHint "Only strings and lists are both comparable and appendable."
584+ [ D.toSimpleHint "Only strings and lists are both comparable and appendable."
585 ]
585 ]
586
586
587 T.Number ->
587 T.Number ->
588 case tipe of
588 case tipe of
589 T.Type home name _ | T.isString home name ->
589 T.Type home name _ | T.isString home name ->
590− [ H.toFancyHint ["Try","using",H.green"String.toInt","to","convert","it","to","a","number?"]
590+ [ D.toFancyHint ["Try","using",D.green"String.toInt","to","convert","it","to","a","number?"]
591 ]
591 ]
592
592
593 _ ->
593 _ ->
594− [ H.toFancyHint ["Only",H.green "Int","and",H.green "Float","values","work","as","numbers."]
594+ [ D.toFancyHint ["Only",D.green "Int","and",D.green "Float","values","work","as","numbers."]
595 ]
595 ]
596
596
597
597
598−badRigidSuper :: T.Super -> String -> [H.Doc]
598+badRigidSuper :: T.Super -> String -> [D.Doc]
599badRigidSuper super aThing =
599badRigidSuper super aThing =
600 let
600 let
601 (superType, manyThings) =
601 (superType, manyThings) =
@@ -605,16 +605,16 @@ badRigidSuper super aThing =
605 T.Appendable -> ("appendable", "strings AND lists")
605 T.Appendable -> ("appendable", "strings AND lists")
606 T.CompAppend -> ("compappend", "strings AND lists")
606 T.CompAppend -> ("compappend", "strings AND lists")
607 in
607 in
608− [ H.toSimpleHint $
608+ [ D.toSimpleHint $
609 "The `" ++ superType ++ "` in your type annotation is saying that "
609 "The `" ++ superType ++ "` in your type annotation is saying that "
610 ++ manyThings ++ " can flow through, but your code is saying it specifically wants "
610 ++ manyThings ++ " can flow through, but your code is saying it specifically wants "
611 ++ aThing ++ ". Maybe change your type annotation to\
611 ++ aThing ++ ". Maybe change your type annotation to\
612 \ be more specific? Maybe change the code to be more general?"
612 \ be more specific? Maybe change the code to be more general?"
613− , H.reflowLink "Read" "type-annotations" "for more advice!"
613+ , D.reflowLink "Read" "type-annotations" "for more advice!"
614 ]
614 ]
615
615
616
616
617−badFlexFlexSuper :: T.Super -> T.Super -> [H.Doc]
617+badFlexFlexSuper :: T.Super -> T.Super -> [D.Doc]
618badFlexFlexSuper s1 s2 =
618badFlexFlexSuper s1 s2 =
619 let
619 let
620 likeThis super =
620 likeThis super =
@@ -624,7 +624,7 @@ badFlexFlexSuper s1 s2 =
624 T.CompAppend -> "a compappend"
624 T.CompAppend -> "a compappend"
625 T.Appendable -> "appendable"
625 T.Appendable -> "appendable"
626 in
626 in
627− [ H.toSimpleHint $
627+ [ D.toSimpleHint $
628 "There are no values in Elm that are both"
628 "There are no values in Elm that are both"
629 ++ likeThis s1 ++ " and " ++ likeThis s2 ++ "."
629 ++ likeThis s1 ++ " and " ++ likeThis s2 ++ "."
630 ]
630 ]
@@ -656,13 +656,13 @@ toExprReport source localizer exprRegion category tipe expected =
656 FromAnnotation name _arity subContext expectedType ->
656 FromAnnotation name _arity subContext expectedType ->
657 Report.toCodeSnippet source exprRegion Nothing
657 Report.toCodeSnippet source exprRegion Nothing
658 (
658 (
659− H.reflow $
659+ D.reflow $
660 case subContext of
660 case subContext of
661 TypedIfBranch index ->
661 TypedIfBranch index ->
662− "Something is off with the " <> H.ordinalize (Index.toHuman index) <> " branch of this `if` expression:"
662+ "Something is off with the " <> D.ordinalize (Index.toHuman index) <> " branch of this `if` expression:"
663
663
664 TypedCaseBranch index ->
664 TypedCaseBranch index ->
665− "Something is off with the " <> H.ordinalize (Index.toHuman index) <> " branch of this `case` expression:"
665+ "Something is off with the " <> D.ordinalize (Index.toHuman index) <> " branch of this `case` expression:"
666
666
667 TypedBody ->
667 TypedBody ->
668 "Something is off with the body of the `" <> N.toString name <> "` definition:"
668 "Something is off with the body of the `" <> N.toString name <> "` definition:"
@@ -672,10 +672,10 @@ toExprReport source localizer exprRegion category tipe expected =
672 toDescription category $
672 toDescription category $
673 case subContext of
673 case subContext of
674 TypedIfBranch index ->
674 TypedIfBranch index ->
675− "The " <> H.ordinalize (Index.toHuman index) <> " branch is"
675+ "The " <> D.ordinalize (Index.toHuman index) <> " branch is"
676
676
677 TypedCaseBranch index ->
677 TypedCaseBranch index ->
678− "The " <> H.ordinalize (Index.toHuman index) <> " branch is"
678+ "The " <> D.ordinalize (Index.toHuman index) <> " branch is"
679
679
680 TypedBody ->
680 TypedBody ->
681 "The body is"
681 "The body is"
@@ -691,17 +691,17 @@ toExprReport source localizer exprRegion category tipe expected =
691 ListEntry index ->
691 ListEntry index ->
692 Report.toCodeSnippet source region (Just exprRegion)
692 Report.toCodeSnippet source region (Just exprRegion)
693 (
693 (
694− H.reflow $
694+ D.reflow $
695− "The " <> H.ordinalize (Index.toHuman index) <> " element of this list does not match all the previous elements:"
695+ "The " <> D.ordinalize (Index.toHuman index) <> " element of this list does not match all the previous elements:"
696 ,
696 ,
697 typeComparison localizer tipe expectedType
697 typeComparison localizer tipe expectedType
698 (
698 (
699 toDescription category $
699 toDescription category $
700− "The " <> H.ordinalize (Index.toHuman index) <> " element is"
700+ "The " <> D.ordinalize (Index.toHuman index) <> " element is"
701 ,
701 ,
702 "But all the previous elements in the list are:"
702 "But all the previous elements in the list are:"
703 ,
703 ,
704− [ H.toSimpleHint $
704+ [ D.toSimpleHint $
705 "Everything in the list needs to be the same type of value.\
705 "Everything in the list needs to be the same type of value.\
706 \ This way you never run into unexpected values partway through.\
706 \ This way you never run into unexpected values partway through.\
707 \ To mix different types in a single list, create a \"union type\" as\
707 \ To mix different types in a single list, create a \"union type\" as\
@@ -717,11 +717,11 @@ toExprReport source localizer exprRegion category tipe expected =
717 ,
717 ,
718 loneType localizer tipe expectedType
718 loneType localizer tipe expectedType
719 (
719 (
720− H.reflow $ toDescription category "It is"
720+ D.reflow $ toDescription category "It is"
721 ,
721 ,
722− [ H.fillSep
722+ [ D.fillSep
723 ["But","I","only","now","how","to","negate"
723 ["But","I","only","now","how","to","negate"
724− ,H.dullyellow "Int","and",H.dullyellow "Float","values."
724+ ,D.dullyellow "Int","and",D.dullyellow "Float","values."
725 ]
725 ]
726 ]
726 ]
727 )
727 )
@@ -746,9 +746,9 @@ toExprReport source localizer exprRegion category tipe expected =
746 ,
746 ,
747 loneType localizer tipe expectedType
747 loneType localizer tipe expectedType
748 (
748 (
749− H.reflow $ toDescription category "It is"
749+ D.reflow $ toDescription category "It is"
750 ,
750 ,
751− [ H.fillSep ["But","I","need","this","`if`","condition","to","be","a",H.dullyellow "Bool","value."]
751+ [ D.fillSep ["But","I","need","this","`if`","condition","to","be","a",D.dullyellow "Bool","value."]
752 ]
752 ]
753 )
753 )
754 )
754 )
@@ -756,17 +756,17 @@ toExprReport source localizer exprRegion category tipe expected =
756 IfBranch index ->
756 IfBranch index ->
757 Report.toCodeSnippet source region (Just exprRegion)
757 Report.toCodeSnippet source region (Just exprRegion)
758 (
758 (
759− H.reflow $
759+ D.reflow $
760− "The " <> H.ordinalize (Index.toHuman index) <> " branch of this `if` does not match all the previous branches:"
760+ "The " <> D.ordinalize (Index.toHuman index) <> " branch of this `if` does not match all the previous branches:"
761 ,
761 ,
762 typeComparison localizer tipe expectedType
762 typeComparison localizer tipe expectedType
763 (
763 (
764 toDescription category $
764 toDescription category $
765− "The " <> H.ordinalize (Index.toHuman index) <> " branch is"
765+ "The " <> D.ordinalize (Index.toHuman index) <> " branch is"
766 ,
766 ,
767 "But all the previous branches result in:"
767 "But all the previous branches result in:"
768 ,
768 ,
769− [ H.link "Hint"
769+ [ D.link "Hint"
770 "All branches in an `if` must produce the same type of values. This way, no\
770 "All branches in an `if` must produce the same type of values. This way, no\
771 \ matter which branch we take, the result is always a consistent shape. Read"
771 \ matter which branch we take, the result is always a consistent shape. Read"
772 "union-types"
772 "union-types"
@@ -778,17 +778,17 @@ toExprReport source localizer exprRegion category tipe expected =
778 CaseBranch index ->
778 CaseBranch index ->
779 Report.toCodeSnippet source region (Just exprRegion)
779 Report.toCodeSnippet source region (Just exprRegion)
780 (
780 (
781− H.reflow $
781+ D.reflow $
782− "The " <> H.ordinalize (Index.toHuman index) <> " branch of this `case` does not match all the previous branches:"
782+ "The " <> D.ordinalize (Index.toHuman index) <> " branch of this `case` does not match all the previous branches:"
783 ,
783 ,
784 typeComparison localizer tipe expectedType
784 typeComparison localizer tipe expectedType
785 (
785 (
786 toDescription category $
786 toDescription category $
787− "The " <> H.ordinalize (Index.toHuman index) <> " branch is"
787+ "The " <> D.ordinalize (Index.toHuman index) <> " branch is"
788 ,
788 ,
789 "But all the previous branches result in:"
789 "But all the previous branches result in:"
790 ,
790 ,
791− [ H.link "Hint"
791+ [ D.link "Hint"
792 "All branches in a `case` must produce the same type of values. This way, no\
792 "All branches in a `case` must produce the same type of values. This way, no\
793 \ matter which branch we take, the result is always a consistent shape. Read"
793 \ matter which branch we take, the result is always a consistent shape. Read"
794 "union-types"
794 "union-types"
@@ -801,33 +801,33 @@ toExprReport source localizer exprRegion category tipe expected =
801 case countArgs tipe of
801 case countArgs tipe of
802 0 ->
802 0 ->
803 Report.toCodeSnippet source region (Just exprRegion)
803 Report.toCodeSnippet source region (Just exprRegion)
804− ( H.reflow $
804+ ( D.reflow $
805 case maybeFuncName of
805 case maybeFuncName of
806 NoName -> "This is not a function:"
806 NoName -> "This is not a function:"
807 FuncName name -> "The `" <> N.toString name <> "` value is not a function:"
807 FuncName name -> "The `" <> N.toString name <> "` value is not a function:"
808 CtorName name -> "The `" <> N.toString name <> "` value is not a function:"
808 CtorName name -> "The `" <> N.toString name <> "` value is not a function:"
809 OpName op -> "The (" <> N.toString op <> ") operator is not a function:"
809 OpName op -> "The (" <> N.toString op <> ") operator is not a function:"
810 ,
810 ,
811− H.stack $
811+ D.stack $
812 [ "It has type:"
812 [ "It has type:"
813− , H.indent 4 $ H.dullyellow $ T.toDoc localizer RT.None tipe
813+ , D.indent 4 $ D.dullyellow $ T.toDoc localizer RT.None tipe
814− , H.reflow $ "So it cannot accept arguments, but it got " <> show numArgs <> " anyway."
814+ , D.reflow $ "So it cannot accept arguments, but it got " <> show numArgs <> " anyway."
815 ]
815 ]
816 )
816 )
817
817
818 n ->
818 n ->
819 Report.toCodeSnippet source region (Just exprRegion)
819 Report.toCodeSnippet source region (Just exprRegion)
820− ( H.reflow $
820+ ( D.reflow $
821 case maybeFuncName of
821 case maybeFuncName of
822 NoName -> "This function was given too many arguments:"
822 NoName -> "This function was given too many arguments:"
823 FuncName name -> "The `" <> N.toString name <> "` function was given too many arguments:"
823 FuncName name -> "The `" <> N.toString name <> "` function was given too many arguments:"
824 CtorName name -> "The `" <> N.toString name <> "` constructor was given too many arguments:"
824 CtorName name -> "The `" <> N.toString name <> "` constructor was given too many arguments:"
825 OpName op -> "The (" <> N.toString op <> ") operator was given too many arguments:"
825 OpName op -> "The (" <> N.toString op <> ") operator was given too many arguments:"
826 ,
826 ,
827− H.stack $
827+ D.stack $
828 [ "It has type:"
828 [ "It has type:"
829− , H.indent 4 $ H.dullyellow $ T.toDoc localizer RT.None tipe
829+ , D.indent 4 $ D.dullyellow $ T.toDoc localizer RT.None tipe
830− , H.reflow $ "So it expects " <> H.args n <> ", but it got " <> show numArgs <> " instead."
830+ , D.reflow $ "So it expects " <> D.args n <> ", but it got " <> show numArgs <> " instead."
831 ]
831 ]
832 )
832 )
833
833
@@ -842,20 +842,20 @@ toExprReport source localizer exprRegion category tipe expected =
842 in
842 in
843 Report.toCodeSnippet source region (Just exprRegion)
843 Report.toCodeSnippet source region (Just exprRegion)
844 (
844 (
845− H.reflow $
845+ D.reflow $
846− "The " <> H.ordinalize (Index.toHuman index) <> " argument to " <> thisFunction <> " is not what I expect:"
846+ "The " <> D.ordinalize (Index.toHuman index) <> " argument to " <> thisFunction <> " is not what I expect:"
847 ,
847 ,
848 typeComparison localizer tipe expectedType
848 typeComparison localizer tipe expectedType
849 (
849 (
850 toDescription category "This argument is"
850 toDescription category "This argument is"
851 ,
851 ,
852− "But " <> thisFunction <> " needs the " <> H.ordinalize (Index.toHuman index)
852+ "But " <> thisFunction <> " needs the " <> D.ordinalize (Index.toHuman index)
853 <> " argument to be:"
853 <> " argument to be:"
854 ,
854 ,
855 if Index.toHuman index == 1 then
855 if Index.toHuman index == 1 then
856 []
856 []
857 else
857 else
858− [ H.toSimpleHint $
858+ [ D.toSimpleHint $
859 "I always figure out the argument types from left to right. If an argument\
859 "I always figure out the argument types from left to right. If an argument\
860 \ is acceptable, I assume it is “correct” and move on. So the problem may\
860 \ is acceptable, I assume it is “correct” and move on. So the problem may\
861 \ actually be in one of the previous arguments!"
861 \ actually be in one of the previous arguments!"
@@ -868,19 +868,19 @@ toExprReport source localizer exprRegion category tipe expected =
868 0 ->
868 0 ->
869 Report.toCodeSnippet source region (Just exprRegion)
869 Report.toCodeSnippet source region (Just exprRegion)
870 (
870 (
871− H.reflow $
871+ D.reflow $
872 case maybeName of
872 case maybeName of
873 NoName ->
873 NoName ->
874− "You are giving " <> H.args numGivenArgs <> " to something that is not a function!"
874+ "You are giving " <> D.args numGivenArgs <> " to something that is not a function!"
875
875
876 FuncName name ->
876 FuncName name ->
877− "`" <> N.toString name <> "` is not a function, but you are giving it " <> H.args numGivenArgs <> "!"
877+ "`" <> N.toString name <> "` is not a function, but you are giving it " <> D.args numGivenArgs <> "!"
878
878
879 CtorName name ->
879 CtorName name ->
880− "`" <> N.toString name <> "` is not a function, but you are giving it " <> H.args numGivenArgs <> "!"
880+ "`" <> N.toString name <> "` is not a function, but you are giving it " <> D.args numGivenArgs <> "!"
881
881
882 OpName op ->
882 OpName op ->
883− "(" <> N.toString op <> ") is not a function, but you are giving it " <> H.args numGivenArgs <> "!"
883+ "(" <> N.toString op <> ") is not a function, but you are giving it " <> D.args numGivenArgs <> "!"
884 ,
884 ,
885 typeComparison localizer tipe expectedType
885 typeComparison localizer tipe expectedType
886 (
886 (
@@ -897,7 +897,7 @@ toExprReport source localizer exprRegion category tipe expected =
897 OpName op ->
897 OpName op ->
898 "(" <> N.toString op <> ") is a value of type:"
898 "(" <> N.toString op <> ") is a value of type:"
899 ,
899 ,
900− "But you are giving it " <> H.args numGivenArgs <> " as if its type was:"
900+ "But you are giving it " <> D.args numGivenArgs <> " as if its type was:"
901 ,
901 ,
902 [ "Maybe you forgot some parentheses? Or a comma?"
902 [ "Maybe you forgot some parentheses? Or a comma?"
903 ]
903 ]
@@ -922,17 +922,17 @@ toExprReport source localizer exprRegion category tipe expected =
922 in
922 in
923 Report.toCodeSnippet source region (Just exprRegion)
923 Report.toCodeSnippet source region (Just exprRegion)
924 (
924 (
925− H.reflow $
925+ D.reflow $
926 thisFunction <> " is getting too many arguments:"
926 thisFunction <> " is getting too many arguments:"
927 ,
927 ,
928 typeComparison localizer tipe expectedType
928 typeComparison localizer tipe expectedType
929 (
929 (
930− thisFunction <> " is expecting to get " <> H.args numExpectedArgs <> " like this:"
930+ thisFunction <> " is expecting to get " <> D.args numExpectedArgs <> " like this:"
931 ,
931 ,
932− "But you are giving it " <> H.args numGivenArgs <> " as if its type was:"
932+ "But you are giving it " <> D.args numGivenArgs <> " as if its type was:"
933 ,
933 ,
934 [ "Maybe you forgot some parentheses? Or a comma?"
934 [ "Maybe you forgot some parentheses? Or a comma?"
935− , H.toSimpleNote $
935+ , D.toSimpleNote $
936 "I am not good at figuring out which arguments are extra myself. The\
936 "I am not good at figuring out which arguments are extra myself. The\
937 \ problem may even be that the FUNCTION is defined funny, and the arguments are\
937 \ problem may even be that the FUNCTION is defined funny, and the arguments are\
938 \ actually fine. Anyway, I hope I gave enough info to help you figure it out!"
938 \ actually fine. Anyway, I hope I gave enough info to help you figure it out!"
@@ -945,15 +945,15 @@ toExprReport source localizer exprRegion category tipe expected =
945 case tipe of
945 case tipe of
946 T.Record _ _ ->
946 T.Record _ _ ->
947 (
947 (
948− H.reflow $
948+ D.reflow $
949 "This record does not have a `" <> N.toString field <> "` field:"
949 "This record does not have a `" <> N.toString field <> "` field:"
950 ,
950 ,
951 loneType localizer tipe expectedType
951 loneType localizer tipe expectedType
952 (
952 (
953− H.reflow $ "It is a record with this type:"
953+ D.reflow $ "It is a record with this type:"
954 ,
954 ,
955− [ H.fillSep
955+ [ D.fillSep
956− ["Is","the",H.dullyellow ("." <> H.nameToDoc field)
956+ ["Is","the",D.dullyellow ("." <> D.fromName field)
957 ,"field","access","is","misspelled?"
957 ,"field","access","is","misspelled?"
958 ]
958 ]
959 ]
959 ]
@@ -962,14 +962,14 @@ toExprReport source localizer exprRegion category tipe expected =
962
962
963 _ ->
963 _ ->
964 (
964 (
965− H.reflow $
965+ D.reflow $
966 "This is not a record, so it has no fields to access!"
966 "This is not a record, so it has no fields to access!"
967 ,
967 ,
968 loneType localizer tipe expectedType
968 loneType localizer tipe expectedType
969− ( H.reflow $ toDescription category "It is"
969+ ( D.reflow $ toDescription category "It is"
970− , [ H.fillSep
970+ , [ D.fillSep
971 ["But","I","need","a","record","with","a"
971 ["But","I","need","a","record","with","a"
972− ,H.dullyellow (H.nameToDoc field),"field!"
972+ ,D.dullyellow (D.fromName field),"field!"
973 ]
973 ]
974 ]
974 ]
975 )
975 )
@@ -980,7 +980,7 @@ toExprReport source localizer exprRegion category tipe expected =
980 T.Record _ _ ->
980 T.Record _ _ ->
981 Report.toCodeSnippet source region Nothing $
981 Report.toCodeSnippet source region Nothing $
982 (
982 (
983− H.reflow $
983+ D.reflow $
984 "I think there is a typo in one of these field names:"
984 "I think there is a typo in one of these field names:"
985 ,
985 ,
986 typeComparison localizer tipe expectedType
986 typeComparison localizer tipe expectedType
@@ -989,7 +989,7 @@ toExprReport source localizer exprRegion category tipe expected =
989 ,
989 ,
990 "But you are saying it should have these fields:"
990 "But you are saying it should have these fields:"
991 ,
991 ,
992− [ H.reflow "Maybe there is some typo?"
992+ [ D.reflow "Maybe there is some typo?"
993 ]
993 ]
994 )
994 )
995 )
995 )
@@ -1000,8 +1000,8 @@ toExprReport source localizer exprRegion category tipe expected =
1000 "The record update syntax does not work with this value:"
1000 "The record update syntax does not work with this value:"
1001 ,
1001 ,
1002 loneType localizer tipe expectedType
1002 loneType localizer tipe expectedType
1003− ( H.reflow $ toDescription category "It is"
1003+ ( D.reflow $ toDescription category "It is"
1004− , [ H.reflow $ "But I need some kind of record here!"
1004+ , [ D.reflow $ "But I need some kind of record here!"
1005 ]
1005 ]
1006 )
1006 )
1007 )
1007 )
@@ -1009,7 +1009,7 @@ toExprReport source localizer exprRegion category tipe expected =
1009 Destructure ->
1009 Destructure ->
1010 Report.toCodeSnippet source region Nothing
1010 Report.toCodeSnippet source region Nothing
1011 (
1011 (
1012− H.reflow $
1012+ D.reflow $
1013 "I cannot destructure "
1013 "I cannot destructure "
1014 ,
1014 ,
1015 typeComparison localizer tipe expectedType
1015 typeComparison localizer tipe expectedType
@@ -1041,7 +1041,7 @@ countArgs tipe =
1041-- OP LEFT
1041-- OP LEFT
1042
1042
1043
1043
1044−opLeftToDocs :: T.Localizer -> Category -> N.Name -> T.Type -> T.Type -> (H.Doc, H.Doc)
1044+opLeftToDocs :: T.Localizer -> Category -> N.Name -> T.Type -> T.Type -> (D.Doc, D.Doc)
1045opLeftToDocs localizer category op tipe expected =
1045opLeftToDocs localizer category op tipe expected =
1046 case op of
1046 case op of
1047 "+"
1047 "+"
@@ -1070,15 +1070,15 @@ opLeftToDocs localizer category op tipe expected =
1070 ( "The left side of (<|) needs to be a function so I can pipe arguments to it!"
1070 ( "The left side of (<|) needs to be a function so I can pipe arguments to it!"
1071 ,
1071 ,
1072 loneType localizer tipe expected
1072 loneType localizer tipe expected
1073− ( H.reflow $ toDescription category "I am seeing"
1073+ ( D.reflow $ toDescription category "I am seeing"
1074− , [ H.reflow $ "This needs to be some kind of function though!"
1074+ , [ D.reflow $ "This needs to be some kind of function though!"
1075 ]
1075 ]
1076 )
1076 )
1077 )
1077 )
1078
1078
1079 _ ->
1079 _ ->
1080 (
1080 (
1081− H.reflow $
1081+ D.reflow $
1082 "The left argument of (" <> N.toString op <> ") is causing problems:"
1082 "The left argument of (" <> N.toString op <> ") is causing problems:"
1083 ,
1083 ,
1084 typeComparison localizer tipe expected
1084 typeComparison localizer tipe expected
@@ -1097,8 +1097,8 @@ opLeftToDocs localizer category op tipe expected =
1097
1097
1098
1098
1099data RightDocs
1099data RightDocs
1100− = EmphBoth (H.Doc, H.Doc)
1100+ = EmphBoth (D.Doc, D.Doc)
1101− | EmphRight (H.Doc, H.Doc)
1101+ | EmphRight (D.Doc, D.Doc)
1102
1102
1103
1103
1104opRightToDocs :: T.Localizer -> Category -> N.Name -> T.Type -> T.Type -> RightDocs
1104opRightToDocs :: T.Localizer -> Category -> N.Name -> T.Type -> T.Type -> RightDocs
@@ -1146,7 +1146,7 @@ opRightToDocs localizer category op tipe expected =
1146 "<|" ->
1146 "<|" ->
1147 EmphRight
1147 EmphRight
1148 (
1148 (
1149− H.reflow $
1149+ D.reflow $
1150 "I cannot send this through the (<|) pipe:"
1150 "I cannot send this through the (<|) pipe:"
1151 ,
1151 ,
1152 typeComparison localizer tipe expected
1152 typeComparison localizer tipe expected
@@ -1182,7 +1182,7 @@ opRightToDocs localizer category op tipe expected =
1182 "The right side of (|>) needs to be a function so I can pipe arguments to it!"
1182 "The right side of (|>) needs to be a function so I can pipe arguments to it!"
1183 ,
1183 ,
1184 loneType localizer tipe expected
1184 loneType localizer tipe expected
1185− ( H.reflow $ toDescription category $
1185+ ( D.reflow $ toDescription category $
1186 "But instead of a function, I am seeing "
1186 "But instead of a function, I am seeing "
1187 , []
1187 , []
1188 )
1188 )
@@ -1196,7 +1196,7 @@ badOpRightFallback :: T.Localizer -> Category -> N.Name -> T.Type -> T.Type -> R
1196badOpRightFallback localizer category op tipe expected =
1196badOpRightFallback localizer category op tipe expected =
1197 EmphRight
1197 EmphRight
1198 (
1198 (
1199− H.reflow $
1199+ D.reflow $
1200 "The right argument of (" <> N.toString op <> ") is causing problems."
1200 "The right argument of (" <> N.toString op <> ") is causing problems."
1201 ,
1201 ,
1202 typeComparison localizer tipe expected
1202 typeComparison localizer tipe expected
@@ -1205,7 +1205,7 @@ badOpRightFallback localizer category op tipe expected =
1205 ,
1205 ,
1206 "But (" <> N.toString op <> ") needs the right argument to be:"
1206 "But (" <> N.toString op <> ") needs the right argument to be:"
1207 ,
1207 ,
1208− [ H.toSimpleHint $
1208+ [ D.toSimpleHint $
1209 "With operators like (" ++ N.toString op ++ ") I always check the left\
1209 "With operators like (" ++ N.toString op ++ ") I always check the left\
1210 \ side first. If it seems fine, I assume it is correct and check the right\
1210 \ side first. If it seems fine, I assume it is correct and check the right\
1211 \ side. So the problem may be in how the left and right arguments interact!"
1211 \ side. So the problem may be in how the left and right arguments interact!"
@@ -1266,7 +1266,7 @@ badConsRight localizer category tipe expected =
1266 T.Type home2 name2 [expectedElement] | T.isList home2 name2 ->
1266 T.Type home2 name2 [expectedElement] | T.isList home2 name2 ->
1267 EmphBoth
1267 EmphBoth
1268 (
1268 (
1269− H.reflow "I am having trouble with this (::) operator:"
1269+ D.reflow "I am having trouble with this (::) operator:"
1270 ,
1270 ,
1271 typeComparison localizer expectedElement actualElement
1271 typeComparison localizer expectedElement actualElement
1272 (
1272 (
@@ -1276,14 +1276,14 @@ badConsRight localizer category tipe expected =
1276 ,
1276 ,
1277 case expectedElement of
1277 case expectedElement of
1278 T.Type home name [_] | T.isList home name ->
1278 T.Type home name [_] | T.isList home name ->
1279− [ H.toSimpleHint
1279+ [ D.toSimpleHint
1280 "Are you trying to append two lists? The (++) operator\
1280 "Are you trying to append two lists? The (++) operator\
1281 \ appends lists, whereas the (::) operator is only for\
1281 \ appends lists, whereas the (::) operator is only for\
1282 \ adding ONE element to a list."
1282 \ adding ONE element to a list."
1283 ]
1283 ]
1284
1284
1285 _ ->
1285 _ ->
1286− [ H.reflow
1286+ [ D.reflow
1287 "Lists need ALL elements to be the same type though."
1287 "Lists need ALL elements to be the same type though."
1288 ]
1288 ]
1289 )
1289 )
@@ -1295,13 +1295,13 @@ badConsRight localizer category tipe expected =
1295 _ ->
1295 _ ->
1296 EmphRight
1296 EmphRight
1297 (
1297 (
1298− H.reflow "The (::) operator can only add elements onto lists."
1298+ D.reflow "The (::) operator can only add elements onto lists."
1299 ,
1299 ,
1300 loneType localizer tipe expected
1300 loneType localizer tipe expected
1301 (
1301 (
1302− H.reflow $ toDescription category "The right side is"
1302+ D.reflow $ toDescription category "The right side is"
1303 ,
1303 ,
1304− [H.fillSep ["But","(::)","needs","a",H.dullyellow "List","on","the","right."]
1304+ [D.fillSep ["But","(::)","needs","a",D.dullyellow "List","on","the","right."]
1305 ]
1305 ]
1306 )
1306 )
1307 )
1307 )
@@ -1312,7 +1312,7 @@ badConsRight localizer category tipe expected =
1312
1312
1313
1313
1314data AppendType
1314data AppendType
1315− = ANumber H.Doc H.Doc
1315+ = ANumber D.Doc D.Doc
1316 | AString
1316 | AString
1317 | AList
1317 | AList
1318 | AOther
1318 | AOther
@@ -1332,18 +1332,18 @@ toAppendType tipe =
1332 _ -> AOther
1332 _ -> AOther
1333
1333
1334
1334
1335−badAppendLeft :: T.Localizer -> Category -> T.Type -> T.Type -> (H.Doc, H.Doc)
1335+badAppendLeft :: T.Localizer -> Category -> T.Type -> T.Type -> (D.Doc, D.Doc)
1336badAppendLeft localizer category tipe expected =
1336badAppendLeft localizer category tipe expected =
1337 case toAppendType tipe of
1337 case toAppendType tipe of
1338 ANumber thing stringFromThing ->
1338 ANumber thing stringFromThing ->
1339 (
1339 (
1340− H.fillSep
1340+ D.fillSep
1341 ["The","(++)","operator","can","append","List","and","String"
1341 ["The","(++)","operator","can","append","List","and","String"
1342− ,"values,","but","not",H.dullyellow thing,"values","like","this:"
1342+ ,"values,","but","not",D.dullyellow thing,"values","like","this:"
1343 ]
1343 ]
1344 ,
1344 ,
1345− H.fillSep
1345+ D.fillSep
1346− ["Try","using",H.green stringFromThing,"to","turn","it","into","a","string?"
1346+ ["Try","using",D.green stringFromThing,"to","turn","it","into","a","string?"
1347 ,"Or","put","it","in","[]","to","make","it","a","list?"
1347 ,"Or","put","it","in","[]","to","make","it","a","list?"
1348 ,"Or","switch","to","the","(::)","operator?"
1348 ,"Or","switch","to","the","(::)","operator?"
1349 ]
1349 ]
@@ -1351,15 +1351,15 @@ badAppendLeft localizer category tipe expected =
1351
1351
1352 _ ->
1352 _ ->
1353 (
1353 (
1354− H.reflow $
1354+ D.reflow $
1355 "The (++) operator cannot append this type of value:"
1355 "The (++) operator cannot append this type of value:"
1356 ,
1356 ,
1357 loneType localizer tipe expected
1357 loneType localizer tipe expected
1358− ( H.reflow $ toDescription category "I am seeing"
1358+ ( D.reflow $ toDescription category "I am seeing"
1359 ,
1359 ,
1360− [ H.fillSep
1360+ [ D.fillSep
1361 ["But","the","(++)","operator","is","only","for","appending"
1361 ["But","the","(++)","operator","is","only","for","appending"
1362− ,H.dullyellow "List","and",H.dullyellow "String","values."
1362+ ,D.dullyellow "List","and",D.dullyellow "String","values."
1363 ,"Maybe","put","this","value","in","[]","to","make","it","a","list?"
1363 ,"Maybe","put","this","value","in","[]","to","make","it","a","list?"
1364 ]
1364 ]
1365 ]
1365 ]
@@ -1373,13 +1373,13 @@ badAppendRight localizer category tipe expected =
1373 (AString, ANumber thing stringFromThing) ->
1373 (AString, ANumber thing stringFromThing) ->
1374 EmphRight
1374 EmphRight
1375 (
1375 (
1376− H.fillSep
1376+ D.fillSep
1377− ["I","thought","I","was","appending",H.dullyellow "String","values","here,"
1377+ ["I","thought","I","was","appending",D.dullyellow "String","values","here,"
1378− ,"not",H.dullyellow thing,"values","like","this:"
1378+ ,"not",D.dullyellow thing,"values","like","this:"
1379 ]
1379 ]
1380 ,
1380 ,
1381− H.fillSep
1381+ D.fillSep
1382− ["Try","using",H.green stringFromThing
1382+ ["Try","using",D.green stringFromThing
1383 ,"to","turn","it","into","a","string?"
1383 ,"to","turn","it","into","a","string?"
1384 ]
1384 ]
1385 )
1385 )
@@ -1387,23 +1387,23 @@ badAppendRight localizer category tipe expected =
1387 (AList, ANumber thing _) ->
1387 (AList, ANumber thing _) ->
1388 EmphRight
1388 EmphRight
1389 (
1389 (
1390− H.fillSep
1390+ D.fillSep
1391− ["I","thought","I","was","appending",H.dullyellow "List","values","here,"
1391+ ["I","thought","I","was","appending",D.dullyellow "List","values","here,"
1392− ,"not",H.dullyellow thing,"values","like","this:"
1392+ ,"not",D.dullyellow thing,"values","like","this:"
1393 ]
1393 ]
1394 ,
1394 ,
1395− H.reflow "Try putting it in [] to make it a list?"
1395+ D.reflow "Try putting it in [] to make it a list?"
1396 )
1396 )
1397
1397
1398 (AString, AList) ->
1398 (AString, AList) ->
1399 EmphBoth
1399 EmphBoth
1400 (
1400 (
1401− H.reflow $
1401+ D.reflow $
1402 "The (++) operator needs the same type of value on both sides:"
1402 "The (++) operator needs the same type of value on both sides:"
1403 ,
1403 ,
1404− H.fillSep
1404+ D.fillSep
1405− ["I","see","a",H.dullyellow "String","on","the","left","and","a"
1405+ ["I","see","a",D.dullyellow "String","on","the","left","and","a"
1406− ,H.dullyellow "List","on","the","right.","Which","should","it","be?"
1406+ ,D.dullyellow "List","on","the","right.","Which","should","it","be?"
1407 ,"Does","the","string","need","[]","around","it","to","become","a","list?"
1407 ,"Does","the","string","need","[]","around","it","to","become","a","list?"
1408 ]
1408 ]
1409 )
1409 )
@@ -1411,12 +1411,12 @@ badAppendRight localizer category tipe expected =
1411 (AList, AString) ->
1411 (AList, AString) ->
1412 EmphBoth
1412 EmphBoth
1413 (
1413 (
1414− H.reflow $
1414+ D.reflow $
1415 "The (++) operator needs the same type of value on both sides:"
1415 "The (++) operator needs the same type of value on both sides:"
1416 ,
1416 ,
1417− H.fillSep
1417+ D.fillSep
1418− ["I","see","a",H.dullyellow "List","on","the","left","and","a"
1418+ ["I","see","a",D.dullyellow "List","on","the","left","and","a"
1419− ,H.dullyellow "String","on","the","right.","Which","should","it","be?"
1419+ ,D.dullyellow "String","on","the","right.","Which","should","it","be?"
1420 ,"Does","the","string","need","[]","around","it","to","become","a","list?"
1420 ,"Does","the","string","need","[]","around","it","to","become","a","list?"
1421 ]
1421 ]
1422 )
1422 )
@@ -1424,7 +1424,7 @@ badAppendRight localizer category tipe expected =
1424 (_,_) ->
1424 (_,_) ->
1425 EmphBoth
1425 EmphBoth
1426 (
1426 (
1427− H.reflow $
1427+ D.reflow $
1428 "The (++) operator cannot append these two values:"
1428 "The (++) operator cannot append these two values:"
1429 ,
1429 ,
1430 typeComparison localizer expected tipe
1430 typeComparison localizer expected tipe
@@ -1450,14 +1450,14 @@ badCast :: N.Name -> ThisThenThat -> RightDocs
1450badCast op thisThenThat =
1450badCast op thisThenThat =
1451 EmphBoth
1451 EmphBoth
1452 (
1452 (
1453− H.text $
1453+ D.reflow $
1454 "I need both sides of (" <> N.toString op <> ") to be the exact same type. Both Int or both Float."
1454 "I need both sides of (" <> N.toString op <> ") to be the exact same type. Both Int or both Float."
1455 ,
1455 ,
1456 let
1456 let
1457− anInt = ["an", H.dullyellow "Int"]
1457+ anInt = ["an", D.dullyellow "Int"]
1458− aFloat = ["a", H.dullyellow "Float"]
1458+ aFloat = ["a", D.dullyellow "Float"]
1459− toFloat = H.green "toFloat"
1459+ toFloat = D.green "toFloat"
1460− round = H.green "round"
1460+ round = D.green "round"
1461 in
1461 in
1462 case thisThenThat of
1462 case thisThenThat of
1463 FloatInt ->
1463 FloatInt ->
@@ -1468,85 +1468,85 @@ badCast op thisThenThat =
1468 )
1468 )
1469
1469
1470
1470
1471−badCastHelp :: [H.Doc] -> [H.Doc] -> H.Doc -> H.Doc -> H.Doc
1471+badCastHelp :: [D.Doc] -> [D.Doc] -> D.Doc -> D.Doc -> D.Doc
1472badCastHelp anInt aFloat toFloat round =
1472badCastHelp anInt aFloat toFloat round =
1473− H.stack
1473+ D.stack
1474− [ H.fillSep $
1474+ [ D.fillSep $
1475 ["But","I","see"]
1475 ["But","I","see"]
1476 ++ anInt
1476 ++ anInt
1477 ++ ["on","the","left","and"]
1477 ++ ["on","the","left","and"]
1478 ++ aFloat
1478 ++ aFloat
1479 ++ ["on","the","right."]
1479 ++ ["on","the","right."]
1480− , H.fillSep
1480+ , D.fillSep
1481 ["Use",toFloat,"on","the","left","(or",round,"on"
1481 ["Use",toFloat,"on","the","left","(or",round,"on"
1482 ,"the","right)","to","make","both","sides","match!"
1482 ,"the","right)","to","make","both","sides","match!"
1483 ]
1483 ]
1484− , H.link "Note" "Read" "implicit-casts" "to learn why Elm does not implicitly convert Ints to Floats."
1484+ , D.link "Note" "Read" "implicit-casts" "to learn why Elm does not implicitly convert Ints to Floats."
1485 ]
1485 ]
1486
1486
1487
1487
1488−badStringAdd :: (H.Doc, H.Doc)
1488+badStringAdd :: (D.Doc, D.Doc)
1489badStringAdd =
1489badStringAdd =
1490 (
1490 (
1491− H.fillSep ["I","cannot","do","addition","with",H.dullyellow "String","values","like","this","one:"]
1491+ D.fillSep ["I","cannot","do","addition","with",D.dullyellow "String","values","like","this","one:"]
1492 ,
1492 ,
1493− H.stack
1493+ D.stack
1494− [ H.fillSep
1494+ [ D.fillSep
1495− ["The","(+)","operator","only","works","with",H.dullyellow "Int","and",H.dullyellow "Float","values."
1495+ ["The","(+)","operator","only","works","with",D.dullyellow "Int","and",D.dullyellow "Float","values."
1496 ]
1496 ]
1497− , H.toFancyHint
1497+ , D.toFancyHint
1498− ["Switch","to","the",H.green "(++)","operator","to","append","strings!"
1498+ ["Switch","to","the",D.green "(++)","operator","to","append","strings!"
1499 ]
1499 ]
1500 ]
1500 ]
1501 )
1501 )
1502
1502
1503
1503
1504−badListAdd :: T.Localizer -> Category -> String -> T.Type -> T.Type -> (H.Doc, H.Doc)
1504+badListAdd :: T.Localizer -> Category -> String -> T.Type -> T.Type -> (D.Doc, D.Doc)
1505badListAdd localizer category direction tipe expected =
1505badListAdd localizer category direction tipe expected =
1506 (
1506 (
1507 "I cannot do addition with lists:"
1507 "I cannot do addition with lists:"
1508 ,
1508 ,
1509 loneType localizer tipe expected
1509 loneType localizer tipe expected
1510 (
1510 (
1511− H.reflow $ toDescription category $
1511+ D.reflow $ toDescription category $
1512 "The " <> direction <> " side of (+) is"
1512 "The " <> direction <> " side of (+) is"
1513 ,
1513 ,
1514− [ H.fillSep
1514+ [ D.fillSep
1515− ["But","(+)","only","works","with",H.dullyellow "Int","and",H.dullyellow "Float","values."
1515+ ["But","(+)","only","works","with",D.dullyellow "Int","and",D.dullyellow "Float","values."
1516 ]
1516 ]
1517− , H.toFancyHint
1517+ , D.toFancyHint
1518− ["Switch","to","the",H.green "(++)","operator","to","append","lists!"
1518+ ["Switch","to","the",D.green "(++)","operator","to","append","lists!"
1519 ]
1519 ]
1520 ]
1520 ]
1521 )
1521 )
1522 )
1522 )
1523
1523
1524
1524
1525−badListMul :: T.Localizer -> Category -> String -> T.Type -> T.Type -> (H.Doc, H.Doc)
1525+badListMul :: T.Localizer -> Category -> String -> T.Type -> T.Type -> (D.Doc, D.Doc)
1526badListMul localizer category direction tipe expected =
1526badListMul localizer category direction tipe expected =
1527 badMath localizer category "Multiplication" direction "*" tipe expected
1527 badMath localizer category "Multiplication" direction "*" tipe expected
1528 [
1528 [
1529− H.toFancyHint
1529+ D.toFancyHint
1530 [ "Maybe", "you", "want"
1530 [ "Maybe", "you", "want"
1531− , H.green "List.repeat"
1531+ , D.green "List.repeat"
1532 , "to", "build","a","list","of","repeated","values?"
1532 , "to", "build","a","list","of","repeated","values?"
1533 ]
1533 ]
1534 ]
1534 ]
1535
1535
1536
1536
1537−badMath :: T.Localizer -> Category -> String -> String -> String -> T.Type -> T.Type -> [H.Doc] -> (H.Doc, H.Doc)
1537+badMath :: T.Localizer -> Category -> String -> String -> String -> T.Type -> T.Type -> [D.Doc] -> (D.Doc, D.Doc)
1538badMath localizer category operation direction op tipe expected otherHints =
1538badMath localizer category operation direction op tipe expected otherHints =
1539 (
1539 (
1540− H.reflow $
1540+ D.reflow $
1541 operation ++ " does not work with this value:"
1541 operation ++ " does not work with this value:"
1542 ,
1542 ,
1543 loneType localizer tipe expected
1543 loneType localizer tipe expected
1544− ( H.reflow $ toDescription category $
1544+ ( D.reflow $ toDescription category $
1545 "The " <> direction <> " side of (" <> op <> ") is"
1545 "The " <> direction <> " side of (" <> op <> ") is"
1546 ,
1546 ,
1547− [ H.fillSep
1547+ [ D.fillSep
1548− ["But","(" <> H.text op <> ")","only","works","with"
1548+ ["But","(" <> D.fromString op <> ")","only","works","with"
1549− ,H.dullyellow "Int","and",H.dullyellow "Float","values."
1549+ ,D.dullyellow "Int","and",D.dullyellow "Float","values."
1550 ]
1550 ]
1551 ]
1551 ]
1552 ++ otherHints
1552 ++ otherHints
@@ -1554,33 +1554,33 @@ badMath localizer category operation direction op tipe expected otherHints =
1554 )
1554 )
1555
1555
1556
1556
1557−badFDiv :: T.Localizer -> H.Doc -> T.Type -> T.Type -> (H.Doc, H.Doc)
1557+badFDiv :: T.Localizer -> D.Doc -> T.Type -> T.Type -> (D.Doc, D.Doc)
1558badFDiv localizer direction tipe expected =
1558badFDiv localizer direction tipe expected =
1559 (
1559 (
1560− H.reflow $
1560+ D.reflow $
1561 "The (/) operator is specifically for floating-point division:"
1561 "The (/) operator is specifically for floating-point division:"
1562 ,
1562 ,
1563 if isInt tipe then
1563 if isInt tipe then
1564− H.stack
1564+ D.stack
1565− [ H.fillSep
1565+ [ D.fillSep
1566 ["The",direction,"side","of","(/)","must","be","a"
1566 ["The",direction,"side","of","(/)","must","be","a"
1567− ,H.dullyellow "Float" <> ","
1567+ ,D.dullyellow "Float" <> ","
1568− ,"but","I","am","seeing","an",H.dullyellow "Int" <> "."
1568+ ,"but","I","am","seeing","an",D.dullyellow "Int" <> "."
1569 ,"I","recommend:"
1569 ,"I","recommend:"
1570 ]
1570 ]
1571− , H.vcat
1571+ , D.vcat
1572− [ H.green "toFloat" <> " for explicit conversions " <> H.black "(toFloat 5 / 2) == 2.5"
1572+ [ D.green "toFloat" <> " for explicit conversions " <> D.black "(toFloat 5 / 2) == 2.5"
1573− , H.green "(//) " <> " for integer division " <> H.black "(5 // 2) == 2"
1573+ , D.green "(//) " <> " for integer division " <> D.black "(5 // 2) == 2"
1574 ]
1574 ]
1575− , H.link "Note" "Read" "implicit-casts" "to learn why Elm does not implicitly convert Ints to Floats."
1575+ , D.link "Note" "Read" "implicit-casts" "to learn why Elm does not implicitly convert Ints to Floats."
1576 ]
1576 ]
1577
1577
1578 else
1578 else
1579 loneType localizer tipe expected
1579 loneType localizer tipe expected
1580 (
1580 (
1581− H.fillSep
1581+ D.fillSep
1582 ["The",direction,"side","of","(/)","must","be","a"
1582 ["The",direction,"side","of","(/)","must","be","a"
1583− ,H.dullyellow "Float" <> ","
1583+ ,D.dullyellow "Float" <> ","
1584 ,"but","instead","I","am","seeing:"
1584 ,"but","instead","I","am","seeing:"
1585 ]
1585 ]
1586 , []
1586 , []
@@ -1588,35 +1588,35 @@ badFDiv localizer direction tipe expected =
1588 )
1588 )
1589
1589
1590
1590
1591−badIDiv :: T.Localizer -> H.Doc -> T.Type -> T.Type -> (H.Doc, H.Doc)
1591+badIDiv :: T.Localizer -> D.Doc -> T.Type -> T.Type -> (D.Doc, D.Doc)
1592badIDiv localizer direction tipe expected =
1592badIDiv localizer direction tipe expected =
1593 (
1593 (
1594− H.reflow $
1594+ D.reflow $
1595 "The (//) operator is specifically for integer division:"
1595 "The (//) operator is specifically for integer division:"
1596 ,
1596 ,
1597 if isFloat tipe then
1597 if isFloat tipe then
1598− H.stack
1598+ D.stack
1599− [ H.fillSep
1599+ [ D.fillSep
1600 ["The",direction,"side","of","(//)","must","be","an"
1600 ["The",direction,"side","of","(//)","must","be","an"
1601− ,H.dullyellow "Int" <> ","
1601+ ,D.dullyellow "Int" <> ","
1602− ,"but","I","am","seeing","a",H.dullyellow "Float" <> "."
1602+ ,"but","I","am","seeing","a",D.dullyellow "Float" <> "."
1603 ,"I","recommend","doing","the","conversion","explicitly"
1603 ,"I","recommend","doing","the","conversion","explicitly"
1604 ,"with","one","of","these","functions:"
1604 ,"with","one","of","these","functions:"
1605 ]
1605 ]
1606− , H.vcat
1606+ , D.vcat
1607− [ H.green "round" <> " 3.5 == 4"
1607+ [ D.green "round" <> " 3.5 == 4"
1608− , H.green "floor" <> " 3.5 == 3"
1608+ , D.green "floor" <> " 3.5 == 3"
1609− , H.green "ceiling" <> " 3.5 == 4"
1609+ , D.green "ceiling" <> " 3.5 == 4"
1610− , H.green "truncate" <> " 3.5 == 3"
1610+ , D.green "truncate" <> " 3.5 == 3"
1611 ]
1611 ]
1612− , H.link "Note" "Read" "implicit-casts" "to learn why Elm does not implicitly convert Ints to Floats."
1612+ , D.link "Note" "Read" "implicit-casts" "to learn why Elm does not implicitly convert Ints to Floats."
1613 ]
1613 ]
1614 else
1614 else
1615 loneType localizer tipe expected
1615 loneType localizer tipe expected
1616 (
1616 (
1617− H.fillSep
1617+ D.fillSep
1618 ["The",direction,"side","of","(//)","must","be","an"
1618 ["The",direction,"side","of","(//)","must","be","an"
1619− ,H.dullyellow "Int" <> ","
1619+ ,D.dullyellow "Int" <> ","
1620 ,"but","instead","I","am","seeing:"
1620 ,"but","instead","I","am","seeing:"
1621 ]
1621 ]
1622 , []
1622 , []
@@ -1628,17 +1628,17 @@ badIDiv localizer direction tipe expected =
1628-- BAD BOOLS
1628-- BAD BOOLS
1629
1629
1630
1630
1631−badBool :: T.Localizer -> H.Doc -> H.Doc -> T.Type -> T.Type -> (H.Doc, H.Doc)
1631+badBool :: T.Localizer -> D.Doc -> D.Doc -> T.Type -> T.Type -> (D.Doc, D.Doc)
1632badBool localizer op direction tipe expected =
1632badBool localizer op direction tipe expected =
1633 (
1633 (
1634− H.reflow $
1634+ D.reflow $
1635 "I am struggling with this boolean operation:"
1635 "I am struggling with this boolean operation:"
1636 ,
1636 ,
1637 loneType localizer tipe expected
1637 loneType localizer tipe expected
1638 (
1638 (
1639− H.fillSep
1639+ D.fillSep
1640 ["Both","sides","of","(" <> op <> ")","must","be"
1640 ["Both","sides","of","(" <> op <> ")","must","be"
1641− ,H.dullyellow "Bool","values,","but","the",direction,"side","is:"
1641+ ,D.dullyellow "Bool","values,","but","the",direction,"side","is:"
1642 ]
1642 ]
1643 ,
1643 ,
1644 []
1644 []
@@ -1650,24 +1650,24 @@ badBool localizer op direction tipe expected =
1650-- BAD COMPARISON
1650-- BAD COMPARISON
1651
1651
1652
1652
1653−badCompLeft :: T.Localizer -> Category -> String -> String -> T.Type -> T.Type -> (H.Doc, H.Doc)
1653+badCompLeft :: T.Localizer -> Category -> String -> String -> T.Type -> T.Type -> (D.Doc, D.Doc)
1654badCompLeft localizer category op direction tipe expected =
1654badCompLeft localizer category op direction tipe expected =
1655 (
1655 (
1656− H.reflow $
1656+ D.reflow $
1657 "I cannot do a comparison with this value:"
1657 "I cannot do a comparison with this value:"
1658 ,
1658 ,
1659 loneType localizer tipe expected
1659 loneType localizer tipe expected
1660 (
1660 (
1661− H.reflow $ toDescription category $
1661+ D.reflow $ toDescription category $
1662 "The " <> direction <> " side of (" <> op <> ") is"
1662 "The " <> direction <> " side of (" <> op <> ") is"
1663 ,
1663 ,
1664− [ H.fillSep
1664+ [ D.fillSep
1665− ["But","(" <> H.text op <> ")","only","works","on"
1665+ ["But","(" <> D.fromString op <> ")","only","works","on"
1666− ,H.dullyellow "Int" <> ","
1666+ ,D.dullyellow "Int" <> ","
1667− ,H.dullyellow "Float" <> ","
1667+ ,D.dullyellow "Float" <> ","
1668− ,H.dullyellow "Char" <> ","
1668+ ,D.dullyellow "Char" <> ","
1669 ,"and"
1669 ,"and"
1670− ,H.dullyellow "String"
1670+ ,D.dullyellow "String"
1671 ,"values.","It","can","work","on","lists","and","tuples"
1671 ,"values.","It","can","work","on","lists","and","tuples"
1672 ,"of","comparable","values","as","well,","but","it","is"
1672 ,"of","comparable","values","as","well,","but","it","is"
1673 ,"usually","better","to","find","a","different","path."
1673 ,"usually","better","to","find","a","different","path."
@@ -1681,7 +1681,7 @@ badCompRight :: T.Localizer -> String -> T.Type -> T.Type -> RightDocs
1681badCompRight localizer op tipe expected =
1681badCompRight localizer op tipe expected =
1682 EmphBoth
1682 EmphBoth
1683 (
1683 (
1684− H.reflow $
1684+ D.reflow $
1685 "I need both sides of (" <> op <> ") to be the same type:"
1685 "I need both sides of (" <> op <> ") to be the same type:"
1686 ,
1686 ,
1687 typeComparison localizer expected tipe
1687 typeComparison localizer expected tipe
@@ -1690,7 +1690,7 @@ badCompRight localizer op tipe expected =
1690 ,
1690 ,
1691 "But the right side is:"
1691 "But the right side is:"
1692 ,
1692 ,
1693− [ H.reflow $
1693+ [ D.reflow $
1694 "I cannot compare different types though! Which side of (" <> op <> ") is the problem?"
1694 "I cannot compare different types though! Which side of (" <> op <> ") is the problem?"
1695 ]
1695 ]
1696 )
1696 )
@@ -1705,7 +1705,7 @@ badEquality :: T.Localizer -> String -> T.Type -> T.Type -> RightDocs
1705badEquality localizer op tipe expected =
1705badEquality localizer op tipe expected =
1706 EmphBoth
1706 EmphBoth
1707 (
1707 (
1708− H.reflow $
1708+ D.reflow $
1709 "I need both sides of (" <> op <> ") to be the same type:"
1709 "I need both sides of (" <> op <> ") to be the same type:"
1710 ,
1710 ,
1711 typeComparison localizer expected tipe
1711 typeComparison localizer expected tipe
@@ -1715,12 +1715,12 @@ badEquality localizer op tipe expected =
1715 "But the right side is:"
1715 "But the right side is:"
1716 ,
1716 ,
1717 if isFloat tipe || isFloat expected then
1717 if isFloat tipe || isFloat expected then
1718− [ H.toSimpleNote $
1718+ [ D.toSimpleNote $
1719 "Equality on floats is not 100% reliable due to the design of IEEE 754. I\
1719 "Equality on floats is not 100% reliable due to the design of IEEE 754. I\
1720 \ recommend a check like (abs (x - y) < 0.0001) instead."
1720 \ recommend a check like (abs (x - y) < 0.0001) instead."
1721 ]
1721 ]
1722 else
1722 else
1723− [ H.reflow $
1723+ [ D.reflow $
1724 "Different types can never be equal though! Which side is messed up?"
1724 "Different types can never be equal though! Which side is messed up?"
1725 ]
1725 ]
1726 )
1726 )
@@ -1736,15 +1736,15 @@ toInfiniteReport source localizer region name overallType =
1736 Report.Report "INFINITE TYPE" region [] $
1736 Report.Report "INFINITE TYPE" region [] $
1737 Report.toCodeSnippet source region Nothing
1737 Report.toCodeSnippet source region Nothing
1738 (
1738 (
1739− H.reflow $
1739+ D.reflow $
1740 "I am inferring a weird self-referential type for " <> N.toString name <> ":"
1740 "I am inferring a weird self-referential type for " <> N.toString name <> ":"
1741 ,
1741 ,
1742− H.stack
1742+ D.stack
1743− [ H.reflow $
1743+ [ D.reflow $
1744 "Here is my best effort at writing down the type. You will see ∞ for\
1744 "Here is my best effort at writing down the type. You will see ∞ for\
1745 \ parts of the type that repeat something already printed out infinitely."
1745 \ parts of the type that repeat something already printed out infinitely."
1746− , H.indent 4 (H.dullyellow (T.toDoc localizer RT.None overallType))
1746+ , D.indent 4 (D.dullyellow (T.toDoc localizer RT.None overallType))
1747− , H.reflowLink
1747+ , D.reflowLink
1748 "Staring at the type is usually not so helpful, so I recommend reading the hints at"
1748 "Staring at the type is usually not so helpful, so I recommend reading the hints at"
1749 "infinite-type"
1749 "infinite-type"
1750 "to get unstuck."
1750 "to get unstuck."
compiler/src/Reporting/Render/Code.hs+15−17
@@ -12,8 +12,9 @@ module Reporting.Render.Code
12
12
13import qualified Data.List as List
13import qualified Data.List as List
14import qualified Data.Text as Text
14import qualified Data.Text as Text
15−import Text.PrettyPrint.ANSI.Leijen (Doc, (<>), hardline, dullred, empty, text)
16
15
16+import Reporting.Doc (Doc, (<>))
17+import qualified Reporting.Doc as D
17import qualified Reporting.Region as R
18import qualified Reporting.Region as R
18
19
19
20
@@ -40,11 +41,6 @@ toSource source =
40 f a
41 f a
41
42
42
43
43−(<==>) :: Doc -> Doc -> Doc
44−(<==>) a b =
45− a <> hardline <> b
46−
47−
48render :: Source -> R.Region -> Maybe R.Region -> Doc
44render :: Source -> R.Region -> Maybe R.Region -> Doc
49render (Source sourceLines) region@(R.Region start end) maybeSubRegion =
45render (Source sourceLines) region@(R.Region start end) maybeSubRegion =
50 let
46 let
@@ -64,7 +60,7 @@ render (Source sourceLines) region@(R.Region start end) maybeSubRegion =
64 in
60 in
65 case makeUnderline width endLine smallerRegion of
61 case makeUnderline width endLine smallerRegion of
66 Nothing ->
62 Nothing ->
67− drawLines True width smallerRegion relevantLines empty
63+ drawLines True width smallerRegion relevantLines D.empty
68
64
69 Just underline ->
65 Just underline ->
70 drawLines False width smallerRegion relevantLines underline
66 drawLines False width smallerRegion relevantLines underline
@@ -80,7 +76,7 @@ makeUnderline width realEndLine (R.Region (R.Position start c1) (R.Position end
80 spaces = replicate (c1 + width + 1) ' '
76 spaces = replicate (c1 + width + 1) ' '
81 zigzag = replicate (max 1 (c2 - c1)) '^'
77 zigzag = replicate (max 1 (c2 - c1)) '^'
82 in
78 in
83− Just (text spaces <> dullred (text zigzag))
79+ Just (D.fromString spaces <> D.dullred (D.fromString zigzag))
84
80
85
81
86drawLines :: Bool -> Int -> R.Region -> [(Int, Text.Text)] -> Doc -> Doc
82drawLines :: Bool -> Int -> R.Region -> [(Int, Text.Text)] -> Doc -> Doc
@@ -89,13 +85,14 @@ drawLines addZigZag width (R.Region start end) sourceLines finalLine =
89 (R.Position startLine _) = start
85 (R.Position startLine _) = start
90 (R.Position endLine _) = end
86 (R.Position endLine _) = end
91 in
87 in
92− foldr (<==>) finalLine $
88+ D.vcat $
93− map (drawLine addZigZag width startLine endLine) sourceLines
89+ map (drawLine addZigZag width startLine endLine) sourceLines
90+ ++ [finalLine]
94
91
95
92
96drawLine :: Bool -> Int -> Int -> Int -> (Int, Text.Text) -> Doc
93drawLine :: Bool -> Int -> Int -> Int -> (Int, Text.Text) -> Doc
97drawLine addZigZag width startLine endLine (n, line) =
94drawLine addZigZag width startLine endLine (n, line) =
98− addLineNumber addZigZag width startLine endLine n (text (Text.unpack line))
95+ addLineNumber addZigZag width startLine endLine n (D.fromText line)
99
96
100
97
101addLineNumber :: Bool -> Int -> Int -> Int -> Int -> Doc -> Doc
98addLineNumber :: Bool -> Int -> Int -> Int -> Int -> Doc -> Doc
@@ -109,11 +106,11 @@ addLineNumber addZigZag width start end n line =
109
106
110 spacer =
107 spacer =
111 if addZigZag && start <= n && n <= end then
108 if addZigZag && start <= n && n <= end then
112− dullred ">"
109+ D.dullred ">"
113 else
110 else
114 " "
111 " "
115 in
112 in
116− text lineNumber <> spacer <> line
113+ D.fromString lineNumber <> spacer <> line
117
114
118
115
119
116
@@ -142,10 +139,11 @@ renderPair source@(Source sourceLines) region1 region2 =
142 (Just line) = List.lookup startRow1 sourceLines
139 (Just line) = List.lookup startRow1 sourceLines
143 in
140 in
144 OneLine $
141 OneLine $
142+ D.vcat
145− text lineNumber <> "| " <> text (Text.unpack line)
143+ [ D.fromString lineNumber <> "| " <> D.fromText line
146− <> hardline
147− <> text spaces1 <> dullred (text zigzag1)
144+ , D.fromString spaces1 <> D.dullred (D.fromString zigzag1) <>
148− <> text spaces2 <> dullred (text zigzag2)
145+ D.fromString spaces2 <> D.dullred (D.fromString zigzag2)
146+ ]
149
147
150 else
148 else
151 TwoChunks
149 TwoChunks
compiler/src/Reporting/Render/Type.hs+25−25
@@ -21,8 +21,8 @@ import qualified AST.Canonical as Can
21import qualified AST.Module.Name as ModuleName
21import qualified AST.Module.Name as ModuleName
22import qualified Elm.Name as N
22import qualified Elm.Name as N
23import qualified Reporting.Annotation as A
23import qualified Reporting.Annotation as A
24−import qualified Reporting.Helpers as H
24+import qualified Reporting.Doc as D
25−import Reporting.Helpers ( Doc, (<+>), (<>) )
25+import Reporting.Doc ( Doc, (<+>), (<>) )
26
26
27
27
28
28
@@ -39,12 +39,12 @@ lambda :: Context -> Doc -> Doc -> [Doc] -> Doc
39lambda context arg1 arg2 args =
39lambda context arg1 arg2 args =
40 let
40 let
41 lambdaDoc =
41 lambdaDoc =
42− H.sep (arg1 : map ("->" <+>) (arg2:args))
42+ D.sep (arg1 : map ("->" <+>) (arg2:args))
43 in
43 in
44 case context of
44 case context of
45 None -> lambdaDoc
45 None -> lambdaDoc
46− Func -> H.cat [ "(", lambdaDoc, ")" ]
46+ Func -> D.cat [ "(", lambdaDoc, ")" ]
47− App -> H.cat [ "(", lambdaDoc, ")" ]
47+ App -> D.cat [ "(", lambdaDoc, ")" ]
48
48
49
49
50apply :: Context -> Doc -> [Doc] -> Doc
50apply :: Context -> Doc -> [Doc] -> Doc
@@ -56,10 +56,10 @@ apply context name args =
56 _:_ ->
56 _:_ ->
57 let
57 let
58 applyDoc =
58 applyDoc =
59− H.hang 4 (H.sep (name : args))
59+ D.hang 4 (D.sep (name : args))
60 in
60 in
61 case context of
61 case context of
62− App -> H.cat [ "(", applyDoc, ")" ]
62+ App -> D.cat [ "(", applyDoc, ")" ]
63 Func -> applyDoc
63 Func -> applyDoc
64 None -> applyDoc
64 None -> applyDoc
65
65
@@ -70,7 +70,7 @@ tuple a b cs =
70 entries =
70 entries =
71 zipWith (<+>) ("(" : repeat ",") (a:b:cs)
71 zipWith (<+>) ("(" : repeat ",") (a:b:cs)
72 in
72 in
73− H.sep [ H.cat entries, ")" ]
73+ D.sep [ D.cat entries, ")" ]
74
74
75
75
76record :: [(Doc, Doc)] -> Maybe Doc -> Doc
76record :: [(Doc, Doc)] -> Maybe Doc -> Doc
@@ -80,16 +80,16 @@ record entries maybeExt =
80 "{}"
80 "{}"
81
81
82 (fields, Nothing) ->
82 (fields, Nothing) ->
83− H.sep
83+ D.sep
84− [ H.cat (zipWith (<+>) ("{" : repeat ",") fields)
84+ [ D.cat (zipWith (<+>) ("{" : repeat ",") fields)
85 , "}"
85 , "}"
86 ]
86 ]
87
87
88 (fields, Just ext) ->
88 (fields, Just ext) ->
89− H.sep
89+ D.sep
90− [ H.hang 4 $ H.sep $
90+ [ D.hang 4 $ D.sep $
91 [ "{" <+> ext
91 [ "{" <+> ext
92− , H.cat (zipWith (<+>) ("|" : repeat ",") fields)
92+ , D.cat (zipWith (<+>) ("|" : repeat ",") fields)
93 ]
93 ]
94 , "}"
94 , "}"
95 ]
95 ]
@@ -97,7 +97,7 @@ record entries maybeExt =
97
97
98entryToDoc :: (Doc, Doc) -> Doc
98entryToDoc :: (Doc, Doc) -> Doc
99entryToDoc (fieldName, fieldType) =
99entryToDoc (fieldName, fieldType) =
100− H.hang 4 (H.sep [ fieldName <+> ":", fieldType ])
100+ D.hang 4 (D.sep [ fieldName <+> ":", fieldType ])
101
101
102
102
103recordSnippet :: (Doc, Doc) -> [(Doc, Doc)] -> Doc
103recordSnippet :: (Doc, Doc) -> [(Doc, Doc)] -> Doc
@@ -106,7 +106,7 @@ recordSnippet entry entries =
106 field = "{" <+> entryToDoc entry
106 field = "{" <+> entryToDoc entry
107 fields = zipWith (<+>) (repeat ",") (map entryToDoc entries ++ ["..."])
107 fields = zipWith (<+>) (repeat ",") (map entryToDoc entries ++ ["..."])
108 in
108 in
109− H.sep [ H.cat (field:fields), "}" ]
109+ D.sep [ D.cat (field:fields), "}" ]
110
110
111
111
112
112
@@ -126,22 +126,22 @@ srcToDoc context (A.At _ tipe) =
126 (map (srcToDoc Func) rest)
126 (map (srcToDoc Func) rest)
127
127
128 Src.TVar name ->
128 Src.TVar name ->
129− H.nameToDoc name
129+ D.fromName name
130
130
131 Src.TType _ name args ->
131 Src.TType _ name args ->
132 apply context
132 apply context
133− (H.nameToDoc name)
133+ (D.fromName name)
134 (map (srcToDoc App) args)
134 (map (srcToDoc App) args)
135
135
136 Src.TTypeQual _ home name args ->
136 Src.TTypeQual _ home name args ->
137 apply context
137 apply context
138− (H.nameToDoc home <> "." <> H.nameToDoc name)
138+ (D.fromName home <> "." <> D.fromName name)
139 (map (srcToDoc App) args)
139 (map (srcToDoc App) args)
140
140
141 Src.TRecord fields ext ->
141 Src.TRecord fields ext ->
142 record
142 record
143 (map fieldToDocs fields)
143 (map fieldToDocs fields)
144− (fmap (H.nameToDoc . A.toValue) ext)
144+ (fmap (D.fromName . A.toValue) ext)
145
145
146 Src.TUnit ->
146 Src.TUnit ->
147 "()"
147 "()"
@@ -155,7 +155,7 @@ srcToDoc context (A.At _ tipe) =
155
155
156fieldToDocs :: (A.Located N.Name, Src.Type) -> (Doc, Doc)
156fieldToDocs :: (A.Located N.Name, Src.Type) -> (Doc, Doc)
157fieldToDocs (A.At _ fieldName, fieldType) =
157fieldToDocs (A.At _ fieldName, fieldType) =
158− ( H.nameToDoc fieldName
158+ ( D.fromName fieldName
159 , srcToDoc None fieldType
159 , srcToDoc None fieldType
160 )
160 )
161
161
@@ -190,17 +190,17 @@ canToDoc context tipe =
190 (map (canToDoc Func) rest)
190 (map (canToDoc Func) rest)
191
191
192 Can.TVar name ->
192 Can.TVar name ->
193− H.nameToDoc name
193+ D.fromName name
194
194
195 Can.TType (ModuleName.Canonical _ home) name args ->
195 Can.TType (ModuleName.Canonical _ home) name args ->
196 apply context
196 apply context
197− (H.nameToDoc home <> "." <> H.nameToDoc name)
197+ (D.fromName home <> "." <> D.fromName name)
198 (map (canToDoc App) args)
198 (map (canToDoc App) args)
199
199
200 Can.TRecord fields ext ->
200 Can.TRecord fields ext ->
201 record
201 record
202 (map entryToDocs (Map.toList fields))
202 (map entryToDocs (Map.toList fields))
203− (fmap H.nameToDoc ext)
203+ (fmap D.fromName ext)
204
204
205 Can.TUnit ->
205 Can.TUnit ->
206 "()"
206 "()"
@@ -213,13 +213,13 @@ canToDoc context tipe =
213
213
214 Can.TAlias (ModuleName.Canonical _ home) name args _ ->
214 Can.TAlias (ModuleName.Canonical _ home) name args _ ->
215 apply context
215 apply context
216− (H.nameToDoc home <> "." <> H.nameToDoc name)
216+ (D.fromName home <> "." <> D.fromName name)
217 (map (canToDoc App . snd) args)
217 (map (canToDoc App . snd) args)
218
218
219
219
220entryToDocs :: (N.Name, Can.Type) -> (Doc, Doc)
220entryToDocs :: (N.Name, Can.Type) -> (Doc, Doc)
221entryToDocs (name, tipe) =
221entryToDocs (name, tipe) =
222− (H.nameToDoc name, canToDoc None tipe)
222+ (D.fromName name, canToDoc None tipe)
223
223
224
224
225collectArgs :: Can.Type -> (Can.Type, [Can.Type])
225collectArgs :: Can.Type -> (Can.Type, [Can.Type])
compiler/src/Reporting/Warning.hs+10−10
@@ -13,11 +13,11 @@ import Data.Monoid ((<>))
13import qualified AST.Canonical as Can
13import qualified AST.Canonical as Can
14import qualified AST.Utils.Type as Type
14import qualified AST.Utils.Type as Type
15import qualified Elm.Name as N
15import qualified Elm.Name as N
16+import qualified Reporting.Doc as D
16import qualified Reporting.Region as R
17import qualified Reporting.Region as R
17import qualified Reporting.Report as Report
18import qualified Reporting.Report as Report
18import qualified Reporting.Render.Code as Code
19import qualified Reporting.Render.Code as Code
19import qualified Reporting.Render.Type as RT
20import qualified Reporting.Render.Type as RT
20−import qualified Reporting.Helpers as H
21
21
22
22
23
23
@@ -44,7 +44,7 @@ toReport source warning =
44 Report.Report "unused import" region [] $
44 Report.Report "unused import" region [] $
45 Report.toCodeSnippet source region Nothing
45 Report.toCodeSnippet source region Nothing
46 (
46 (
47− H.reflow $
47+ D.reflow $
48 "Nothing from the `" <> N.toString moduleName <> "` module is used in this file."
48 "Nothing from the `" <> N.toString moduleName <> "` module is used in this file."
49 ,
49 ,
50 "I recommend removing unused imports."
50 "I recommend removing unused imports."
@@ -55,14 +55,14 @@ toReport source warning =
55 Report.Report title region [] $
55 Report.Report title region [] $
56 Report.toCodeSnippet source region Nothing
56 Report.toCodeSnippet source region Nothing
57 (
57 (
58− H.reflow $
58+ D.reflow $
59 "You are not using `" <> N.toString name <> "` anywhere."
59 "You are not using `" <> N.toString name <> "` anywhere."
60 ,
60 ,
61− H.stack
61+ D.stack
62− [ H.reflow $
62+ [ D.reflow $
63 "Is there a typo? Maybe you intended to use `" <> N.toString name
63 "Is there a typo? Maybe you intended to use `" <> N.toString name
64 <> "` somewhere but typed another name instead?"
64 <> "` somewhere but typed another name instead?"
65− , H.reflow $
65+ , D.reflow $
66 defOrPat context
66 defOrPat context
67 ( "If you are sure there is no typo, remove the definition.\
67 ( "If you are sure there is no typo, remove the definition.\
68 \ This way future readers will not have to wonder why it is there!"
68 \ This way future readers will not have to wonder why it is there!"
@@ -77,7 +77,7 @@ toReport source warning =
77 Report.Report "missing type annotation" region [] $
77 Report.Report "missing type annotation" region [] $
78 Report.toCodeSnippet source region Nothing
78 Report.toCodeSnippet source region Nothing
79 (
79 (
80− H.reflow $
80+ D.reflow $
81 case Type.deepDealias inferredType of
81 case Type.deepDealias inferredType of
82 Can.TLambda _ _ ->
82 Can.TLambda _ _ ->
83 "The `" <> N.toString name <> "` function has no type annotation."
83 "The `" <> N.toString name <> "` function has no type annotation."
@@ -85,10 +85,10 @@ toReport source warning =
85 _ ->
85 _ ->
86 "The `" <> N.toString name <> "` definition has no type annotation."
86 "The `" <> N.toString name <> "` definition has no type annotation."
87 ,
87 ,
88− H.stack
88+ D.stack
89 [ "I inferred the type annotation myself though! You can copy it into your code:"
89 [ "I inferred the type annotation myself though! You can copy it into your code:"
90− , H.green $ H.hang 4 $ H.sep $
90+ , D.green $ D.hang 4 $ D.sep $
91− [ H.nameToDoc name <> " :"
91+ [ D.fromName name <> " :"
92 , RT.canToDoc RT.None inferredType
92 , RT.canToDoc RT.None inferredType
93 ]
93 ]
94 ]
94 ]
compiler/src/Type/Error.hs+45−45
@@ -25,7 +25,7 @@ import Data.Monoid ((<>))
25import qualified AST.Module.Name as ModuleName
25import qualified AST.Module.Name as ModuleName
26import qualified Data.Bag as Bag
26import qualified Data.Bag as Bag
27import qualified Elm.Name as N
27import qualified Elm.Name as N
28−import qualified Reporting.Helpers as H
28+import qualified Reporting.Doc as D
29import qualified Reporting.Render.Type as RT
29import qualified Reporting.Render.Type as RT
30
30
31
31
@@ -78,17 +78,17 @@ iteratedDealias tipe =
78type Localizer = Map.Map (ModuleName.Canonical, N.Name) String
78type Localizer = Map.Map (ModuleName.Canonical, N.Name) String
79
79
80
80
81−nameToDoc :: Localizer -> ModuleName.Canonical -> N.Name -> H.Doc
81+nameToDoc :: Localizer -> ModuleName.Canonical -> N.Name -> D.Doc
82nameToDoc dict home@(ModuleName.Canonical _ moduleName) name =
82nameToDoc dict home@(ModuleName.Canonical _ moduleName) name =
83 case Map.lookup (home, name) dict of
83 case Map.lookup (home, name) dict of
84 Nothing ->
84 Nothing ->
85− H.nameToDoc moduleName <> "." <> H.nameToDoc name
85+ D.fromName moduleName <> "." <> D.fromName name
86
86
87 Just string ->
87 Just string ->
88− H.text string
88+ D.fromString string
89
89
90
90
91−toDoc :: Localizer -> RT.Context -> Type -> H.Doc
91+toDoc :: Localizer -> RT.Context -> Type -> D.Doc
92toDoc dict ctx tipe =
92toDoc dict ctx tipe =
93 case tipe of
93 case tipe of
94 Lambda a b cs ->
94 Lambda a b cs ->
@@ -104,16 +104,16 @@ toDoc dict ctx tipe =
104 "?"
104 "?"
105
105
106 FlexVar name ->
106 FlexVar name ->
107− H.nameToDoc name
107+ D.fromName name
108
108
109 FlexSuper _ name ->
109 FlexSuper _ name ->
110− H.nameToDoc name
110+ D.fromName name
111
111
112 RigidVar name ->
112 RigidVar name ->
113− H.nameToDoc name
113+ D.fromName name
114
114
115 RigidSuper _ name ->
115 RigidSuper _ name ->
116− H.nameToDoc name
116+ D.fromName name
117
117
118 Type home name args ->
118 Type home name args ->
119 RT.apply ctx
119 RT.apply ctx
@@ -123,7 +123,7 @@ toDoc dict ctx tipe =
123 Record fields ext ->
123 Record fields ext ->
124 let
124 let
125 entryToDocs (fieldName, fieldType) =
125 entryToDocs (fieldName, fieldType) =
126− ( H.nameToDoc fieldName, toDoc dict RT.None fieldType )
126+ ( D.fromName fieldName, toDoc dict RT.None fieldType )
127
127
128 fieldDocs =
128 fieldDocs =
129 map entryToDocs (Map.toList fields)
129 map entryToDocs (Map.toList fields)
@@ -131,8 +131,8 @@ toDoc dict ctx tipe =
131 RT.record fieldDocs $
131 RT.record fieldDocs $
132 case ext of
132 case ext of
133 Closed -> Nothing
133 Closed -> Nothing
134− FlexOpen x -> Just (H.nameToDoc x)
134+ FlexOpen x -> Just (D.fromName x)
135− RigidOpen x -> Just (H.nameToDoc x)
135+ RigidOpen x -> Just (D.fromName x)
136
136
137 Unit ->
137 Unit ->
138 "()"
138 "()"
@@ -153,7 +153,7 @@ toDoc dict ctx tipe =
153-- DIFF
153-- DIFF
154
154
155
155
156−toDiffDocs :: Localizer -> Type -> Type -> (H.Doc, H.Doc, [Problem])
156+toDiffDocs :: Localizer -> Type -> Type -> (D.Doc, D.Doc, [Problem])
157toDiffDocs dict a b =
157toDiffDocs dict a b =
158 case diff dict RT.None a b of
158 case diff dict RT.None a b of
159 Similar aDoc bDoc ->
159 Similar aDoc bDoc ->
@@ -217,13 +217,13 @@ data Problem
217-- COMPUTE DIFF
217-- COMPUTE DIFF
218
218
219
219
220−diff :: Localizer -> RT.Context -> Type -> Type -> Diff H.Doc
220+diff :: Localizer -> RT.Context -> Type -> Type -> Diff D.Doc
221diff dict ctx tipe1 tipe2 =
221diff dict ctx tipe1 tipe2 =
222 case (tipe1, tipe2) of
222 case (tipe1, tipe2) of
223− (FlexVar x, FlexVar y) | x == y -> pure (H.nameToDoc x)
223+ (FlexVar x, FlexVar y) | x == y -> pure (D.fromName x)
224− (FlexSuper _ x, FlexSuper _ y) | x == y -> pure (H.nameToDoc x)
224+ (FlexSuper _ x, FlexSuper _ y) | x == y -> pure (D.fromName x)
225− (RigidVar x, RigidVar y) | x == y -> pure (H.nameToDoc x)
225+ (RigidVar x, RigidVar y) | x == y -> pure (D.fromName x)
226− (RigidSuper _ x, RigidSuper _ y) | x == y -> pure (H.nameToDoc x)
226+ (RigidSuper _ x, RigidSuper _ y) | x == y -> pure (D.fromName x)
227
227
228 (Infinite, Infinite) -> pure "∞"
228 (Infinite, Infinite) -> pure "∞"
229 (Error, Error) -> pure "?"
229 (Error, Error) -> pure "?"
@@ -236,8 +236,8 @@ diff dict ctx tipe1 tipe2 =
236 <*>
236 <*>
237 case (maybeC, maybeZ) of
237 case (maybeC, maybeZ) of
238 (Nothing, Nothing) -> pure []
238 (Nothing, Nothing) -> pure []
239− (Just c , Nothing) -> Different [H.dullyellow (toDoc dict RT.None c)] [] Bag.empty
239+ (Just c , Nothing) -> Different [D.dullyellow (toDoc dict RT.None c)] [] Bag.empty
240− (Nothing, Just z ) -> Different [] [H.dullyellow (toDoc dict RT.None z)] Bag.empty
240+ (Nothing, Just z ) -> Different [] [D.dullyellow (toDoc dict RT.None z)] Bag.empty
241 (Just c , Just z ) -> (:[]) <$> diff dict RT.None c z
241 (Just c , Just z ) -> (:[]) <$> diff dict RT.None c z
242
242
243 (Record fields1 ext1, Record fields2 ext2) -> diffRecord dict fields1 ext1 fields2 ext2
243 (Record fields1 ext1, Record fields2 ext2) -> diffRecord dict fields1 ext1 fields2 ext2
@@ -255,8 +255,8 @@ diff dict ctx tipe1 tipe2 =
255
255
256 (Lambda a b cs, Lambda x y zs) -> diffLambda dict ctx (a:b:cs) (x:y:zs)
256 (Lambda a b cs, Lambda x y zs) -> diffLambda dict ctx (a:b:cs) (x:y:zs)
257
257
258− (FlexVar x, other) -> Similar (H.nameToDoc x) (toDoc dict ctx other)
258+ (FlexVar x, other) -> Similar (D.fromName x) (toDoc dict ctx other)
259− (other, FlexVar x) -> Similar (toDoc dict ctx other) (H.nameToDoc x)
259+ (other, FlexVar x) -> Similar (toDoc dict ctx other) (D.fromName x)
260
260
261 pair ->
261 pair ->
262 case pair of
262 case pair of
@@ -268,8 +268,8 @@ diff dict ctx tipe1 tipe2 =
268
268
269 _ ->
269 _ ->
270 let
270 let
271− doc1 = H.dullyellow (toDoc dict ctx tipe1)
271+ doc1 = D.dullyellow (toDoc dict ctx tipe1)
272− doc2 = H.dullyellow (toDoc dict ctx tipe2)
272+ doc2 = D.dullyellow (toDoc dict ctx tipe2)
273 in
273 in
274 Different doc1 doc2 $
274 Different doc1 doc2 $
275 case pair of
275 case pair of
@@ -334,10 +334,10 @@ isSimilar tipe1 tipe2 =
334 Different _ _ _ -> False
334 Different _ _ _ -> False
335
335
336
336
337−yellowApply :: Localizer -> RT.Context -> ModuleName.Canonical -> N.Name -> Type -> H.Doc
337+yellowApply :: Localizer -> RT.Context -> ModuleName.Canonical -> N.Name -> Type -> D.Doc
338yellowApply dict ctx home name tipe =
338yellowApply dict ctx home name tipe =
339 RT.apply ctx
339 RT.apply ctx
340− (H.dullyellow (nameToDoc dict home name))
340+ (D.dullyellow (nameToDoc dict home name))
341 [toDoc dict RT.App tipe]
341 [toDoc dict RT.App tipe]
342
342
343
343
@@ -348,7 +348,7 @@ yellowApply dict ctx home name tipe =
348--
348--
349-- INVARIANT: length types1 >= 2 && length types2 >= 2
349-- INVARIANT: length types1 >= 2 && length types2 >= 2
350--
350--
351−diffLambda :: Localizer -> RT.Context -> [Type] -> [Type] -> Diff H.Doc
351+diffLambda :: Localizer -> RT.Context -> [Type] -> [Type] -> Diff D.Doc
352diffLambda dict ctx types1 types2 =
352diffLambda dict ctx types1 types2 =
353 let
353 let
354 (result1:revArgs1) = reverse types1
354 (result1:revArgs1) = reverse types1
@@ -389,7 +389,7 @@ diffLambda dict ctx types1 types2 =
389--
389--
390-- INVARIANT: length shortRevArgs >= 2 && length longRevArgs >= 2
390-- INVARIANT: length shortRevArgs >= 2 && length longRevArgs >= 2
391--
391--
392−diffArgMismatch :: Localizer -> RT.Context -> [Type] -> H.Doc -> [Type] -> H.Doc -> Diff H.Doc
392+diffArgMismatch :: Localizer -> RT.Context -> [Type] -> D.Doc -> [Type] -> D.Doc -> Diff D.Doc
393diffArgMismatch dict ctx shortRevArgs shortResult longRevArgs longResult =
393diffArgMismatch dict ctx shortRevArgs shortResult longRevArgs longResult =
394 case toGreedyMatch dict shortRevArgs longRevArgs of
394 case toGreedyMatch dict shortRevArgs longRevArgs of
395 Just (GreedyMatch shortRevArgDocs longRevArgDocs) ->
395 Just (GreedyMatch shortRevArgDocs longRevArgDocs) ->
@@ -417,7 +417,7 @@ diffArgMismatch dict ctx shortRevArgs shortResult longRevArgs longResult =
417 Nothing ->
417 Nothing ->
418 let
418 let
419 toYellowDoc tipe =
419 toYellowDoc tipe =
420− H.dullyellow (toDoc dict RT.Func tipe)
420+ D.dullyellow (toDoc dict RT.Func tipe)
421
421
422 (a:b:cs) = reverse (shortResult : map toYellowDoc shortRevArgs)
422 (a:b:cs) = reverse (shortResult : map toYellowDoc shortRevArgs)
423 (x:y:zs) = reverse (longResult : map toYellowDoc longRevArgs )
423 (x:y:zs) = reverse (longResult : map toYellowDoc longRevArgs )
@@ -433,7 +433,7 @@ diffArgMismatch dict ctx shortRevArgs shortResult longRevArgs longResult =
433
433
434
434
435data GreedyMatch =
435data GreedyMatch =
436− GreedyMatch [H.Doc] [H.Doc]
436+ GreedyMatch [D.Doc] [D.Doc]
437
437
438
438
439--
439--
@@ -448,7 +448,7 @@ toGreedyMatchHelp :: Localizer -> [Type] -> [Type] -> GreedyMatch -> Maybe Greed
448toGreedyMatchHelp dict shorterArgs longerArgs match@(GreedyMatch shorterDocs longerDocs) =
448toGreedyMatchHelp dict shorterArgs longerArgs match@(GreedyMatch shorterDocs longerDocs) =
449 let
449 let
450 toYellowDoc tipe =
450 toYellowDoc tipe =
451− H.dullyellow (toDoc dict RT.Func tipe)
451+ D.dullyellow (toDoc dict RT.Func tipe)
452 in
452 in
453 case (shorterArgs, longerArgs) of
453 case (shorterArgs, longerArgs) of
454 (x:xs, y:ys) ->
454 (x:xs, y:ys) ->
@@ -475,7 +475,7 @@ toGreedyMatchHelp dict shorterArgs longerArgs match@(GreedyMatch shorterDocs lon
475-- RECORD DIFFS
475-- RECORD DIFFS
476
476
477
477
478−diffRecord :: Localizer -> Map.Map N.Name Type -> Extension -> Map.Map N.Name Type -> Extension -> Diff H.Doc
478+diffRecord :: Localizer -> Map.Map N.Name Type -> Extension -> Map.Map N.Name Type -> Extension -> Diff D.Doc
479diffRecord dict fields1 ext1 fields2 ext2 =
479diffRecord dict fields1 ext1 fields2 ext2 =
480 let
480 let
481 only1 = Map.keys (Map.difference fields1 fields2)
481 only1 = Map.keys (Map.difference fields1 fields2)
@@ -510,12 +510,12 @@ diffRecord dict fields1 ext1 fields2 ext2 =
510 (Bag.one (FieldMismatch only1 only2))
510 (Bag.one (FieldMismatch only1 only2))
511
511
512
512
513−toOverlapDoc :: (BadOverlap -> H.Doc) -> BadOverlap -> (H.Doc, H.Doc)
513+toOverlapDoc :: (BadOverlap -> D.Doc) -> BadOverlap -> (D.Doc, D.Doc)
514toOverlapDoc getDoc overlap@(BadOverlap field _ _ _) =
514toOverlapDoc getDoc overlap@(BadOverlap field _ _ _) =
515− (H.nameToDoc field, getDoc overlap)
515+ (D.fromName field, getDoc overlap)
516
516
517
517
518−toOverlapRecord :: (BadOverlap -> H.Doc) -> BadOverlap -> [BadOverlap] -> Extension -> H.Doc
518+toOverlapRecord :: (BadOverlap -> D.Doc) -> BadOverlap -> [BadOverlap] -> Extension -> D.Doc
519toOverlapRecord getDoc bad bads ext =
519toOverlapRecord getDoc bad bads ext =
520 let go = toOverlapDoc getDoc in
520 let go = toOverlapDoc getDoc in
521 case ext of
521 case ext of
@@ -524,7 +524,7 @@ toOverlapRecord getDoc bad bads ext =
524 RigidOpen _ -> RT.recordSnippet (go bad) (map go bads)
524 RigidOpen _ -> RT.recordSnippet (go bad) (map go bads)
525
525
526
526
527−toMissingDoc :: Map.Map N.Name t -> [N.Name] -> Extension -> H.Doc
527+toMissingDoc :: Map.Map N.Name t -> [N.Name] -> Extension -> D.Doc
528toMissingDoc allFields uniqueFields ext =
528toMissingDoc allFields uniqueFields ext =
529 case map emphasizeFieldName uniqueFields of
529 case map emphasizeFieldName uniqueFields of
530 [] ->
530 [] ->
@@ -540,12 +540,12 @@ toMissingDoc allFields uniqueFields ext =
540 RigidOpen _ -> RT.recordSnippet doc docs
540 RigidOpen _ -> RT.recordSnippet doc docs
541
541
542
542
543−emphasizeFieldName :: N.Name -> (H.Doc, H.Doc)
543+emphasizeFieldName :: N.Name -> (D.Doc, D.Doc)
544emphasizeFieldName field =
544emphasizeFieldName field =
545− ( H.dullyellow (H.nameToDoc field), "..." )
545+ ( D.dullyellow (D.fromName field), "..." )
546
546
547
547
548−toBoringRecord :: Map.Map N.Name t -> Extension -> H.Doc
548+toBoringRecord :: Map.Map N.Name t -> Extension -> D.Doc
549toBoringRecord fields ext =
549toBoringRecord fields ext =
550 case ext of
550 case ext of
551 Closed -> if Map.null fields then "{}" else "{ ... }"
551 Closed -> if Map.null fields then "{}" else "{ ... }"
@@ -557,11 +557,11 @@ toBoringRecord fields ext =
557-- DIFF RECORD EXTENSION
557-- DIFF RECORD EXTENSION
558
558
559
559
560−diffExt :: Extension -> Extension -> Diff (Maybe H.Doc)
560+diffExt :: Extension -> Extension -> Diff (Maybe D.Doc)
561diffExt ext1 ext2 =
561diffExt ext1 ext2 =
562 let
562 let
563− normal = Just . H.nameToDoc
563+ normal = Just . D.fromName
564− yellow = Just . H.dullyellow . H.nameToDoc
564+ yellow = Just . D.dullyellow . D.fromName
565
565
566 different x y = Different x y Bag.empty
566 different x y = Different x y Bag.empty
567 in
567 in
@@ -596,8 +596,8 @@ diffExt ext1 ext2 =
596data BadOverlap =
596data BadOverlap =
597 BadOverlap
597 BadOverlap
598 { _field :: N.Name
598 { _field :: N.Name
599− , _doc1 :: H.Doc
599+ , _doc1 :: D.Doc
600− , _doc2 :: H.Doc
600+ , _doc2 :: D.Doc
601 , _problems :: Bag.Bag Problem
601 , _problems :: Bag.Bag Problem
602 }
602 }
603
603
@@ -608,7 +608,7 @@ findBadOverlaps dict fields1 fields2 =
608 Map.intersectionWith (diff dict RT.None) fields1 fields2
608 Map.intersectionWith (diff dict RT.None) fields1 fields2
609
609
610
610
611−findBadOverlapsHelp :: [BadOverlap] -> [(N.Name, Diff H.Doc)] -> [BadOverlap]
611+findBadOverlapsHelp :: [BadOverlap] -> [(N.Name, Diff D.Doc)] -> [BadOverlap]
612findBadOverlapsHelp badOverlaps fieldPairs =
612findBadOverlapsHelp badOverlaps fieldPairs =
613 case fieldPairs of
613 case fieldPairs of
614 [] ->
614 [] ->
elm.cabal+4−4
@@ -134,7 +134,6 @@ Executable elm
134 Elm.Header,
134 Elm.Header,
135 Elm.Name,
135 Elm.Name,
136 Elm.Package,
136 Elm.Package,
137− Elm.Utils,
138 Json.Decode,
137 Json.Decode,
139 Json.Encode,
138 Json.Encode,
140
139
@@ -196,6 +195,7 @@ Executable elm
196 Parse.Shader,
195 Parse.Shader,
197 Parse.Type,
196 Parse.Type,
198 Reporting.Annotation,
197 Reporting.Annotation,
198+ Reporting.Doc,
199 Reporting.Error,
199 Reporting.Error,
200 Reporting.Error.Canonicalize,
200 Reporting.Error.Canonicalize,
201 Reporting.Error.Docs,
201 Reporting.Error.Docs,
@@ -203,12 +203,12 @@ Executable elm
203 Reporting.Error.Pattern,
203 Reporting.Error.Pattern,
204 Reporting.Error.Syntax,
204 Reporting.Error.Syntax,
205 Reporting.Error.Type,
205 Reporting.Error.Type,
206− Reporting.Helpers,
207 Reporting.Region,
206 Reporting.Region,
208 Reporting.Render.Code,
207 Reporting.Render.Code,
209 Reporting.Render.Type,
208 Reporting.Render.Type,
210 Reporting.Report,
209 Reporting.Report,
211 Reporting.Result,
210 Reporting.Result,
211+ Reporting.Suggest,
212 Reporting.Warning,
212 Reporting.Warning,
213 Type.Constrain.Expression,
213 Type.Constrain.Expression,
214 Type.Constrain.Module,
214 Type.Constrain.Module,
@@ -224,8 +224,8 @@ Executable elm
224 Paths_elm
224 Paths_elm
225
225
226 Build-depends:
226 Build-depends:
227− ansi-terminal >= 0.7 && < 0.8,
227+ ansi-terminal >= 0.8 && < 0.9,
228− ansi-wl-pprint >= 0.6.7 && < 0.7,
228+ ansi-wl-pprint >= 0.6.8 && < 0.7,
229 base >=4.8 && <5,
229 base >=4.8 && <5,
230 binary >= 0.8 && < 0.9,
230 binary >= 0.8 && < 0.9,
231 bytestring >= 0.9 && < 0.11,
231 bytestring >= 0.9 && < 0.11,
ui/terminal/src/Repl.hs+1−1
@@ -29,7 +29,7 @@ import qualified Elm.Name as N
29import qualified Elm.Project as Project
29import qualified Elm.Project as Project
30import qualified Elm.Package as Pkg
30import qualified Elm.Package as Pkg
31import qualified Elm.PerUserCache as PerUserCache
31import qualified Elm.PerUserCache as PerUserCache
32−import qualified Elm.Utils as Elm
32+import qualified Parse.Repl as Elm
33import qualified Reporting.Task as Task
33import qualified Reporting.Task as Task
34import qualified Reporting.Progress.Repl as Repl
34import qualified Reporting.Progress.Repl as Repl
35
35
ui/terminal/src/Terminal/Args/Error.hs+8−4
@@ -23,7 +23,7 @@ import qualified System.FilePath as FP
23import System.IO (hPutStrLn, stderr)
23import System.IO (hPutStrLn, stderr)
24import qualified Text.PrettyPrint.ANSI.Leijen as P
24import qualified Text.PrettyPrint.ANSI.Leijen as P
25
25
26−import Elm.Utils (nearbyNames, distance)
26+import Reporting.Suggest as Suggest
27import Terminal.Args.Internal
27import Terminal.Args.Internal
28
28
29
29
@@ -235,7 +235,7 @@ exitWithUnknown :: String -> [String] -> IO a
235exitWithUnknown unknown knowns =
235exitWithUnknown unknown knowns =
236 let
236 let
237 suggestions =
237 suggestions =
238− case map toGreen (nearbyNames id unknown knowns) of
238+ case map toGreen (Suggest.nearbyNames id unknown knowns) of
239 [] ->
239 [] ->
240 []
240 []
241
241
@@ -434,7 +434,11 @@ getNearbyFlagsHelp :: String -> Flag a -> (Int, String)
434getNearbyFlagsHelp unknown flag =
434getNearbyFlagsHelp unknown flag =
435 case flag of
435 case flag of
436 OnOff flagName _ ->
436 OnOff flagName _ ->
437− ( distance unknown flagName, "--" ++ flagName )
437+ ( Suggest.distance unknown flagName
438+ , "--" ++ flagName
439+ )
438
440
439 Flag flagName (Parser singular _ _ _ _) _ ->
441 Flag flagName (Parser singular _ _ _ _) _ ->
442+ ( Suggest.distance unknown flagName
440− ( distance unknown flagName, "--" ++ flagName ++ "=" ++ toToken singular )
443+ , "--" ++ flagName ++ "=" ++ toToken singular
444+ )