on master help sign in
Give more specialized error titles
4a5d921Evan Czaplicki
src/Reporting/Error.hs+5−11
@@ -21,21 +21,15 @@ data Error
21toString :: String -> String -> A.Located Error -> String
21toString :: String -> String -> A.Located Error -> String
22toString location source (A.A region err) =
22toString location source (A.A region err) =
23 let
23 let
24− (tag, report) =
24+ report =
25 case err of
25 case err of
26 Syntax syntaxError ->
26 Syntax syntaxError ->
27− ( "SYNTAX ERROR"
28− , Syntax.toReport syntaxError
27+ Syntax.toReport syntaxError
29− )
30
28
31 Canonicalize canonicalizeError ->
29 Canonicalize canonicalizeError ->
32− ( "NAMING ERROR"
33− , Canonicalize.toReport canonicalizeError
30+ Canonicalize.toReport canonicalizeError
34− )
35
31
36 Type typeError ->
32 Type typeError ->
37− ( "TYPE ERROR"
38− , Type.toReport typeError
33+ Type.toReport typeError
39− )
40 in
34 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 =
131
131
132-- TO REPORT
132-- TO REPORT
133
133
134+namingError :: String -> String -> Report.Report
135+namingError pre post =
136+ Report.simple "NAMING ERROR" pre post
137+
138+
134toReport :: Error -> Report.Report
139toReport :: Error -> Report.Report
135toReport err =
140toReport err =
136 case err of
141 case err of
@@ -139,22 +144,22 @@ toReport err =
139 in
144 in
140 case problem of
145 case problem of
141 Ambiguous ->
146 Ambiguous ->
142− Report.simple
147+ namingError
143 ("This usage of " ++ var ++ " is ambiguous.")
148 ("This usage of " ++ var ++ " is ambiguous.")
144 (maybeYouWant suggestions)
149 (maybeYouWant suggestions)
145
150
146 UnknownQualifier qualifier ->
151 UnknownQualifier qualifier ->
147− Report.simple
152+ namingError
148 ("Cannot find " ++ var ++ ", qualifier '" ++ qualifier ++ "' is not in scope.")
153 ("Cannot find " ++ var ++ ", qualifier '" ++ qualifier ++ "' is not in scope.")
149 (maybeYouWant suggestions)
154 (maybeYouWant suggestions)
150
155
151 QualifiedUnknown qualifier ->
156 QualifiedUnknown qualifier ->
152− Report.simple
157+ namingError
153 ("Cannot find " ++ var ++ ", module '" ++ qualifier ++ "' does not expose that value.")
158 ("Cannot find " ++ var ++ ", module '" ++ qualifier ++ "' does not expose that value.")
154 (maybeYouWant suggestions)
159 (maybeYouWant suggestions)
155
160
156 ExposedUnknown ->
161 ExposedUnknown ->
157− Report.simple
162+ namingError
158 ("Cannot find " ++ var)
163 ("Cannot find " ++ var)
159 (maybeYouWant suggestions)
164 (maybeYouWant suggestions)
160
165
@@ -169,7 +174,7 @@ toReport err =
169 argMismatchReport "Type" var expected actual
174 argMismatchReport "Type" var expected actual
170
175
171 SelfRecursive name tvars tipe ->
176 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!" $
173 "Type aliases are just names for more fundamental types, so I go through\n"
178 "Type aliases are just names for more fundamental types, so I go through\n"
174 ++ "and expand them all to know the real underlying type. The problem is that\n"
179 ++ "and expand them all to know the real underlying type. The problem is that\n"
175 ++ "when I expand a recursive type alias, it keeps getting bigger and bigger.\n"
180 ++ "when I expand a recursive type alias, it keeps getting bigger and bigger.\n"
@@ -180,7 +185,7 @@ toReport err =
180 ++ "like List which are recursive, but do not get expanded into infinite types."
185 ++ "like List which are recursive, but do not get expanded into infinite types."
181
186
182 MutuallyRecursive aliases ->
187 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." $
184 "The following type aliases all depend on each other in some way:\n"
189 "The following type aliases all depend on each other in some way:\n"
185 ++ concatMap showName aliases ++ "\n\n"
190 ++ concatMap showName aliases ++ "\n\n"
186 ++ "The problem is that when you try to expand any of these type aliases, they\n"
191 ++ "The problem is that when you try to expand any of these type aliases, they\n"
@@ -195,17 +200,17 @@ toReport err =
195 in
200 in
196 case importError of
201 case importError of
197 ModuleNotFound suggestions ->
202 ModuleNotFound suggestions ->
198− Report.simple
203+ namingError
199 ("Could not find a module named '" ++ moduleName ++ "'")
204 ("Could not find a module named '" ++ moduleName ++ "'")
200 (maybeYouWant (map Module.nameToString suggestions))
205 (maybeYouWant (map Module.nameToString suggestions))
201
206
202 ValueNotFound value suggestions ->
207 ValueNotFound value suggestions ->
203− Report.simple
208+ namingError
204 ("Module '" ++ moduleName ++ "' does not expose '" ++ value ++ "'")
209 ("Module '" ++ moduleName ++ "' does not expose '" ++ value ++ "'")
205 (maybeYouWant suggestions)
210 (maybeYouWant suggestions)
206
211
207 Export name suggestions ->
212 Export name suggestions ->
208− Report.simple
213+ namingError
209 ("Could not export '" ++ name ++ "' which is not defined in this module.")
214 ("Could not export '" ++ name ++ "' which is not defined in this module.")
210 (maybeYouWant suggestions)
215 (maybeYouWant suggestions)
211
216
@@ -225,7 +230,7 @@ toReport err =
225 ++ "Ints, Floats, Bools, Strings, Maybes, Lists, Arrays, Tuples,\n"
230 ++ "Ints, Floats, Bools, Strings, Maybes, Lists, Arrays, Tuples,\n"
226 ++ "Json.Values, and concrete records."
231 ++ "Json.Values, and concrete records."
227 in
232 in
228− Report.simple preHint postHint
233+ Report.simple "PORT ERROR" preHint postHint
229
234
230
235
231argMismatchReport :: String -> Var.Canonical -> Int -> Int -> Report.Report
236argMismatchReport :: String -> Var.Canonical -> Int -> Int -> Report.Report
@@ -239,7 +244,7 @@ argMismatchReport kind var expected actual =
239 postHint =
244 postHint =
240 "Expecting " ++ show expected ++ ", but got " ++ show actual ++ "."
245 "Expecting " ++ show expected ++ ", but got " ++ show actual ++ "."
241 in
246 in
242− Report.Report Nothing preHint postHint
247+ Report.simple "ARGUMENT" preHint postHint
243
248
244
249
245maybeYouWant :: [String] -> String
250maybeYouWant :: [String] -> String
src/Reporting/Error/Syntax.hs+8
@@ -32,11 +32,13 @@ toReport err =
32 case err of
32 case err of
33 Parse messages ->
33 Parse messages ->
34 Report.simple
34 Report.simple
35+ "SYNTAX PROBLEM"
35 "Problem when parsing your code!"
36 "Problem when parsing your code!"
36 (unlines (map parseErrorHint messages))
37 (unlines (map parseErrorHint messages))
37
38
38 InfixDuplicate opName ->
39 InfixDuplicate opName ->
39 Report.simple
40 Report.simple
41+ "INFIX OVERLAP"
40 ("The infix declarations for " ++ operator ++ " must be removed.")
42 ("The infix declarations for " ++ operator ++ " must be removed.")
41 ("The precedence and associativity can only be set in one place, and\n"
43 ("The precedence and associativity can only be set in one place, and\n"
42 ++ "this information has already been set somewhere else."
44 ++ "this information has already been set somewhere else."
@@ -49,6 +51,7 @@ toReport err =
49
51
50 TypeWithoutDefinition valueName ->
52 TypeWithoutDefinition valueName ->
51 Report.simple
53 Report.simple
54+ "MISSING DEFINITION"
52 ("There is a type annotation for '" ++ valueName ++ "' but there"
55 ("There is a type annotation for '" ++ valueName ++ "' but there"
53 ++ "is no corresponding definition!"
56 ++ "is no corresponding definition!"
54 )
57 )
@@ -58,6 +61,7 @@ toReport err =
58
61
59 PortWithoutAnnotation portName ->
62 PortWithoutAnnotation portName ->
60 Report.simple
63 Report.simple
64+ "PORT ERROR"
61 ("Port '" ++ portName ++ "' does not have a type annotation!")
65 ("Port '" ++ portName ++ "' does not have a type annotation!")
62 ("Directly above the port definition, I need something like this:\n\n"
66 ("Directly above the port definition, I need something like this:\n\n"
63 ++ " port " ++ portName ++ " : Signal Int"
67 ++ " port " ++ portName ++ " : Signal Int"
@@ -65,6 +69,7 @@ toReport err =
65
69
66 DuplicateValueDeclaration name ->
70 DuplicateValueDeclaration name ->
67 Report.simple
71 Report.simple
72+ "DUPLICATE DEFINITION"
68 ("Naming multiple top-level values '" ++ name ++ "' makes things\n"
73 ("Naming multiple top-level values '" ++ name ++ "' makes things\n"
69 ++ "ambiguous. When you say '" ++ name ++ "' which one do you want?!"
74 ++ "ambiguous. When you say '" ++ name ++ "' which one do you want?!"
70 )
75 )
@@ -74,6 +79,7 @@ toReport err =
74
79
75 DuplicateTypeDeclaration name ->
80 DuplicateTypeDeclaration name ->
76 Report.simple
81 Report.simple
82+ "DUPLICATE DEFINITION"
77 ("Naming multiple types '" ++ name ++ "' makes things ambiguous\n"
83 ("Naming multiple types '" ++ name ++ "' makes things ambiguous\n"
78 ++ "When you say '" ++ name ++ "' which one do you want?!"
84 ++ "When you say '" ++ name ++ "' which one do you want?!"
79 )
85 )
@@ -83,6 +89,7 @@ toReport err =
83
89
84 DuplicateDefinition name ->
90 DuplicateDefinition name ->
85 Report.simple
91 Report.simple
92+ "DUPLICATE DEFINITION"
86 ("Naming multiple values '" ++ name ++ "' in a single let-expression makes\n"
93 ("Naming multiple values '" ++ name ++ "' in a single let-expression makes\n"
87 ++ "things ambiguous. When you say '" ++ name ++ "' which one do you want?!"
94 ++ "things ambiguous. When you say '" ++ name ++ "' which one do you want?!"
88 )
95 )
@@ -118,6 +125,7 @@ toReport err =
118unboundTypeVars :: String -> String -> [String] -> String -> Report.Report
125unboundTypeVars :: String -> String -> [String] -> String -> Report.Report
119unboundTypeVars typeName tvar tvars revisedDeclaration =
126unboundTypeVars typeName tvar tvars revisedDeclaration =
120 Report.simple
127 Report.simple
128+ "UNBOUND TYPE VARS"
121 ( "Not all type variables in '" ++ typeName ++ "' are listed, making sneaky\n"
129 ( "Not all type variables in '" ++ typeName ++ "' are listed, making sneaky\n"
122 ++ "type errors possible. Unbound type variables include: "
130 ++ "type errors possible. Unbound type variables include: "
123 ++ List.intercalate ", " (tvar:tvars)
131 ++ List.intercalate ", " (tvar:tvars)
src/Reporting/Error/Type.hs+5−7
@@ -58,18 +58,16 @@ toReport err =
58 in
58 in
59 case note of
59 case note of
60 PreNote msg ->
60 PreNote msg ->
61− Report.Report subRegion (preHint ++ "\n\n" ++ msg) postHint
61+ Report.Report "TYPE MISMATCH" subRegion (preHint ++ "\n\n" ++ msg) postHint
62
62
63 NoNote ->
63 NoNote ->
64− Report.Report subRegion preHint postHint
64+ Report.Report "TYPE MISMATCH" subRegion preHint postHint
65
65
66 PostNote msg ->
66 PostNote msg ->
67− Report.Report subRegion preHint (postHint ++ "\n\n" ++ msg)
67+ Report.Report "TYPE MISMATCH" subRegion preHint (postHint ++ "\n\n" ++ msg)
68−
69−
70
68
71 InfiniteType var tipe ->
69 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." $
73 "Maybe you are trying to do some tricky recursion? Try breaking the expression\n"
71 "Maybe you are trying to do some tricky recursion? Try breaking the expression\n"
74 ++ "into smaller pieces. Give each piece a name and try to write down its type.\n\n"
72 ++ "into smaller pieces. Give each piece a name and try to write down its type.\n\n"
75 ++ "Type inference got stuck when type '" ++ var ++ "' needed equal to:\n\n"
73 ++ "Type inference got stuck when type '" ++ var ++ "' needed equal to:\n\n"
@@ -78,7 +76,7 @@ toReport err =
78 ++ "expanded this type, it would just keep getting bigger and bigger."
76 ++ "expanded this type, it would just keep getting bigger and bigger."
79
77
80 BadMain tipe ->
78 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." $
82 "I need an Element, Html, (Signal Element), or (Signal Html) so I can render it\n"
80 "I need an Element, Html, (Signal Element), or (Signal Html) so I can render it\n"
83 ++ "on screen, but you gave me:\n\n"
81 ++ "on screen, but you gave me:\n\n"
84 ++ P.render (P.nest 4 (P.pretty False tipe))
82 ++ 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
9
9
10
10
11data Report = Report
11data Report = Report
12+ { title :: String
12− { highlight :: Maybe R.Region
13+ , highlight :: Maybe R.Region
13 , preHint :: String
14 , preHint :: String
14 , postHint :: String
15 , postHint :: String
15 }
16 }
16
17
17
18
18−simple :: String -> String -> Report
19+simple :: String -> String -> String -> Report
19−simple pre post =
20+simple title pre post =
20− Report Nothing pre post
21+ Report title Nothing pre post
21
22
22
23
23−toString :: String -> String -> R.Region -> Report -> String -> String
24+toString :: String -> R.Region -> Report -> String -> String
24−toString tag location region report source =
25+toString location region report source =
25 concat
26 concat
26− [ messageBar tag location
27+ [ messageBar (title report) location
27 , preHint report ++ "\n\n"
28 , preHint report ++ "\n\n"
28 , grabRegion (highlight report) region source ++ "\n"
29 , grabRegion (highlight report) region source ++ "\n"
29 , postHint report ++ "\n\n\n"
30 , postHint report ++ "\n\n\n"