on master help sign in
Give more specialized error titles
commit4a5d921e148114a6608b5302bc957900fbca3925 authorEvan Czaplicki <info@elm-lang.org> dateSat 9 May 2015, 11:17 (11 years ago) parent42dcc29
5 files changed+42−36
src/Reporting/Error.hs+5−11 src/Reporting/Error/Canonicalize.hs+16−11 src/Reporting/Error/Syntax.hs+8 src/Reporting/Error/Type.hs+5−7 src/Reporting/Report.hs+8−7
src/Reporting/Error.hs+5−11
@@ -21,21 +21,15 @@ data Error
2121toString :: String -> String -> A.Located Error -> String
2222toString location source (A.A region err) =
2323 let
24− (tag, report) =
24+ report =
2525 case err of
2626 Syntax syntaxError ->
27− ( "SYNTAX ERROR"
28− , Syntax.toReport syntaxError
29− )
27+ Syntax.toReport syntaxError
3028
3129 Canonicalize canonicalizeError ->
32− ( "NAMING ERROR"
33− , Canonicalize.toReport canonicalizeError
34− )
30+ Canonicalize.toReport canonicalizeError
3531
3632 Type typeError ->
37− ( "TYPE ERROR"
38− , Type.toReport typeError
39− )
33+ Type.toReport typeError
4034 in
41− Report.toString tag location region report source
35+ Report.toString location region report source
src/Reporting/Error/Canonicalize.hs+16−11
@@ -131,6 +131,11 @@ distance x y =
131131
132132-- TO REPORT
133133
134+namingError :: String -> String -> Report.Report
135+namingError pre post =
136+ Report.simple "NAMING ERROR" pre post
137+
138+
134139toReport :: Error -> Report.Report
135140toReport err =
136141 case err of
@@ -139,22 +144,22 @@ toReport err =
139144 in
140145 case problem of
141146 Ambiguous ->
142− Report.simple
147+ namingError
143148 ("This usage of " ++ var ++ " is ambiguous.")
144149 (maybeYouWant suggestions)
145150
146151 UnknownQualifier qualifier ->
147− Report.simple
152+ namingError
148153 ("Cannot find " ++ var ++ ", qualifier '" ++ qualifier ++ "' is not in scope.")
149154 (maybeYouWant suggestions)
150155
151156 QualifiedUnknown qualifier ->
152− Report.simple
157+ namingError
153158 ("Cannot find " ++ var ++ ", module '" ++ qualifier ++ "' does not expose that value.")
154159 (maybeYouWant suggestions)
155160
156161 ExposedUnknown ->
157− Report.simple
162+ namingError
158163 ("Cannot find " ++ var)
159164 (maybeYouWant suggestions)
160165
@@ -169,7 +174,7 @@ toReport err =
169174 argMismatchReport "Type" var expected actual
170175
171176 SelfRecursive name tvars tipe ->
172− Report.simple "This type alias is recursive, forming an infinite type!" $
177+ Report.simple "ALIAS PROBLEM" "This type alias is recursive, forming an infinite type!" $
173178 "Type aliases are just names for more fundamental types, so I go through\n"
174179 ++ "and expand them all to know the real underlying type. The problem is that\n"
175180 ++ "when I expand a recursive type alias, it keeps getting bigger and bigger.\n"
@@ -180,7 +185,7 @@ toReport err =
180185 ++ "like List which are recursive, but do not get expanded into infinite types."
181186
182187 MutuallyRecursive aliases ->
183− Report.simple "This type alias is part of a mutually recursive set of type aliases." $
188+ Report.simple "ALIAS PROBLEM" "This type alias is part of a mutually recursive set of type aliases." $
184189 "The following type aliases all depend on each other in some way:\n"
185190 ++ concatMap showName aliases ++ "\n\n"
186191 ++ "The problem is that when you try to expand any of these type aliases, they\n"
@@ -195,17 +200,17 @@ toReport err =
195200 in
196201 case importError of
197202 ModuleNotFound suggestions ->
198− Report.simple
203+ namingError
199204 ("Could not find a module named '" ++ moduleName ++ "'")
200205 (maybeYouWant (map Module.nameToString suggestions))
201206
202207 ValueNotFound value suggestions ->
203− Report.simple
208+ namingError
204209 ("Module '" ++ moduleName ++ "' does not expose '" ++ value ++ "'")
205210 (maybeYouWant suggestions)
206211
207212 Export name suggestions ->
208− Report.simple
213+ namingError
209214 ("Could not export '" ++ name ++ "' which is not defined in this module.")
210215 (maybeYouWant suggestions)
211216
@@ -225,7 +230,7 @@ toReport err =
225230 ++ "Ints, Floats, Bools, Strings, Maybes, Lists, Arrays, Tuples,\n"
226231 ++ "Json.Values, and concrete records."
227232 in
228− Report.simple preHint postHint
233+ Report.simple "PORT ERROR" preHint postHint
229234
230235
231236argMismatchReport :: String -> Var.Canonical -> Int -> Int -> Report.Report
@@ -239,7 +244,7 @@ argMismatchReport kind var expected actual =
239244 postHint =
240245 "Expecting " ++ show expected ++ ", but got " ++ show actual ++ "."
241246 in
242− Report.Report Nothing preHint postHint
247+ Report.simple "ARGUMENT" preHint postHint
243248
244249
245250maybeYouWant :: [String] -> String
src/Reporting/Error/Syntax.hs+8
@@ -32,11 +32,13 @@ toReport err =
3232 case err of
3333 Parse messages ->
3434 Report.simple
35+ "SYNTAX PROBLEM"
3536 "Problem when parsing your code!"
3637 (unlines (map parseErrorHint messages))
3738
3839 InfixDuplicate opName ->
3940 Report.simple
41+ "INFIX OVERLAP"
4042 ("The infix declarations for " ++ operator ++ " must be removed.")
4143 ("The precedence and associativity can only be set in one place, and\n"
4244 ++ "this information has already been set somewhere else."
@@ -49,6 +51,7 @@ toReport err =
4951
5052 TypeWithoutDefinition valueName ->
5153 Report.simple
54+ "MISSING DEFINITION"
5255 ("There is a type annotation for '" ++ valueName ++ "' but there"
5356 ++ "is no corresponding definition!"
5457 )
@@ -58,6 +61,7 @@ toReport err =
5861
5962 PortWithoutAnnotation portName ->
6063 Report.simple
64+ "PORT ERROR"
6165 ("Port '" ++ portName ++ "' does not have a type annotation!")
6266 ("Directly above the port definition, I need something like this:\n\n"
6367 ++ " port " ++ portName ++ " : Signal Int"
@@ -65,6 +69,7 @@ toReport err =
6569
6670 DuplicateValueDeclaration name ->
6771 Report.simple
72+ "DUPLICATE DEFINITION"
6873 ("Naming multiple top-level values '" ++ name ++ "' makes things\n"
6974 ++ "ambiguous. When you say '" ++ name ++ "' which one do you want?!"
7075 )
@@ -74,6 +79,7 @@ toReport err =
7479
7580 DuplicateTypeDeclaration name ->
7681 Report.simple
82+ "DUPLICATE DEFINITION"
7783 ("Naming multiple types '" ++ name ++ "' makes things ambiguous\n"
7884 ++ "When you say '" ++ name ++ "' which one do you want?!"
7985 )
@@ -83,6 +89,7 @@ toReport err =
8389
8490 DuplicateDefinition name ->
8591 Report.simple
92+ "DUPLICATE DEFINITION"
8693 ("Naming multiple values '" ++ name ++ "' in a single let-expression makes\n"
8794 ++ "things ambiguous. When you say '" ++ name ++ "' which one do you want?!"
8895 )
@@ -118,6 +125,7 @@ toReport err =
118125unboundTypeVars :: String -> String -> [String] -> String -> Report.Report
119126unboundTypeVars typeName tvar tvars revisedDeclaration =
120127 Report.simple
128+ "UNBOUND TYPE VARS"
121129 ( "Not all type variables in '" ++ typeName ++ "' are listed, making sneaky\n"
122130 ++ "type errors possible. Unbound type variables include: "
123131 ++ List.intercalate ", " (tvar:tvars)
src/Reporting/Error/Type.hs+5−7
@@ -58,18 +58,16 @@ toReport err =
5858 in
5959 case note of
6060 PreNote msg ->
61− Report.Report subRegion (preHint ++ "\n\n" ++ msg) postHint
61+ Report.Report "TYPE MISMATCH" subRegion (preHint ++ "\n\n" ++ msg) postHint
6262
6363 NoNote ->
64− Report.Report subRegion preHint postHint
64+ Report.Report "TYPE MISMATCH" subRegion preHint postHint
6565
6666 PostNote msg ->
67− Report.Report subRegion preHint (postHint ++ "\n\n" ++ msg)
68−
69−
67+ Report.Report "TYPE MISMATCH" subRegion preHint (postHint ++ "\n\n" ++ msg)
7068
7169 InfiniteType var tipe ->
72− Report.simple "This expression is leading me to infer an infinite type." $
70+ Report.simple "INFINITE TYPE" "This expression is leading me to infer an infinite type." $
7371 "Maybe you are trying to do some tricky recursion? Try breaking the expression\n"
7472 ++ "into smaller pieces. Give each piece a name and try to write down its type.\n\n"
7573 ++ "Type inference got stuck when type '" ++ var ++ "' needed equal to:\n\n"
@@ -78,7 +76,7 @@ toReport err =
7876 ++ "expanded this type, it would just keep getting bigger and bigger."
7977
8078 BadMain tipe ->
81− Report.simple "The 'main' value has an unsupported type." $
79+ Report.simple "BAD MAIN TYPE" "The 'main' value has an unsupported type." $
8280 "I need an Element, Html, (Signal Element), or (Signal Html) so I can render it\n"
8381 ++ "on screen, but you gave me:\n\n"
8482 ++ P.render (P.nest 4 (P.pretty False tipe))
src/Reporting/Report.hs+8−7
@@ -9,21 +9,22 @@ import qualified Reporting.Region as R
99
1010
1111data Report = Report
12− { highlight :: Maybe R.Region
12+ { title :: String
13+ , highlight :: Maybe R.Region
1314 , preHint :: String
1415 , postHint :: String
1516 }
1617
1718
18−simple :: String -> String -> Report
19−simple pre post =
20− Report Nothing pre post
19+simple :: String -> String -> String -> Report
20+simple title pre post =
21+ Report title Nothing pre post
2122
2223
23−toString :: String -> String -> R.Region -> Report -> String -> String
24−toString tag location region report source =
24+toString :: String -> R.Region -> Report -> String -> String
25+toString location region report source =
2526 concat
26− [ messageBar tag location
27+ [ messageBar (title report) location
2728 , preHint report ++ "\n\n"
2829 , grabRegion (highlight report) region source ++ "\n"
2930 , postHint report ++ "\n\n\n"