on master help sign in
Make ordinal hints a bit nicer
7fbdee0Evan Czaplicki
src/Reporting/Error/Type.hs+29−14
@@ -72,10 +72,11 @@ toReport dealiaser err =
72 case err of
72 case err of
73 Mismatch (MismatchInfo hint leftType rightType note) ->
73 Mismatch (MismatchInfo hint leftType rightType note) ->
74 let
74 let
75− (subRegion, preHint) = hintToString hint
75+ (subRegion, preHint, maybePostHint) = hintToString hint
76
76
77 postHint =
77 postHint =
78 maybe "" (++"\n\n") note
78 maybe "" (++"\n\n") note
79+ ++ maybe "" (++"\n\n") maybePostHint
79 ++ "As I infer the type of values flowing through your program, I see a conflict\n"
80 ++ "As I infer the type of values flowing through your program, I see a conflict\n"
80 ++ "between these two types:\n\n"
81 ++ "between these two types:\n\n"
81 ++ P.render (P.nest 4 (P.pretty dealiaser False leftType))
82 ++ P.render (P.nest 4 (P.pretty dealiaser False leftType))
@@ -111,79 +112,84 @@ toReport dealiaser err =
111 ++ P.render (P.nest 4 (P.pretty dealiaser False tipe))
112 ++ P.render (P.nest 4 (P.pretty dealiaser False tipe))
112
113
113
114
114−hintToString :: Hint -> (Maybe Region.Region, String)
115+hintToString :: Hint -> (Maybe Region.Region, String, Maybe String)
115hintToString hint =
116hintToString hint =
116 case hint of
117 case hint of
117 CaseBranch branchNumber region ->
118 CaseBranch branchNumber region ->
118 ( Just region
119 ( Just region
119− , "The branches of this case-expression return different types of values.\n\n"
120+ , "The " ++ ordinalize branchNumber ++ " branch of this `case` results in an unexpected type of value."
120− ++ "I noticed the mismatch in the " ++ ordinalize branchNumber ++ " branch, but go through and make sure every\n"
121+ , Just "All branches should match so that no matter which one we take, we always get\nback the same type of value."
121− ++ "branch returns the same type of value."
122 )
122 )
123
123
124 Case ->
124 Case ->
125 ( Nothing
125 ( Nothing
126 , "All the branches of this case-expression are consistent, but the overall\n"
126 , "All the branches of this case-expression are consistent, but the overall\n"
127 ++ "type does not match how it is used elsewhere."
127 ++ "type does not match how it is used elsewhere."
128+ , Nothing
128 )
129 )
129
130
130 IfBranches ->
131 IfBranches ->
131 ( Nothing
132 ( Nothing
132− , "The branches of this if-expression return different types of values.\n"
133+ , "The branches of this `if` result in different types of values."
133− ++ "All branches must have the same return type!"
134+ , Just "All branches should match so that no matter which one we take, we always get\nback the same type of value."
134 )
135 )
135
136
136 MultiIfBranch branchNumber region ->
137 MultiIfBranch branchNumber region ->
137 ( Just region
138 ( Just region
138− , "The branches of this if-expression return different types of values.\n\n"
139+ , "The " ++ ordinalize branchNumber ++ " branch of this `if` results in an unexpected type of value."
139− ++ "I noticed the mismatch in the " ++ ordinalize branchNumber ++ " branch, but go through and make sure every\n"
140+ , Just "All branches should match so that no matter which one we take, we always get\nback the same type of value."
140− ++ "branch returns the same type of value."
141 )
141 )
142
142
143 If ->
143 If ->
144 ( Nothing
144 ( Nothing
145 , "All the branches of this if-expression are consistent, but the overall\n"
145 , "All the branches of this if-expression are consistent, but the overall\n"
146 ++ "type does not match how it is used elsewhere."
146 ++ "type does not match how it is used elsewhere."
147+ , Nothing
147 )
148 )
148
149
149 ListElement elementNumber region ->
150 ListElement elementNumber region ->
150 ( Just region
151 ( Just region
151− , "Not all elements of this list are the same type of value.\n\n"
152+ , "The " ++ ordinalize elementNumber ++ " element of this list is an unexpected type of value."
152− ++ "I noticed the mismatch in the " ++ ordinalize elementNumber ++ " element, but go through and make sure every\n"
153+ , Just "All elements should be the same type of value so that we can iterate over the\nlist without running into unexpected values."
153− ++ "element is the same type of value."
154 )
154 )
155
155
156 List ->
156 List ->
157 ( Nothing
157 ( Nothing
158 , "All the elements in this list are the same type, but the overall\n"
158 , "All the elements in this list are the same type, but the overall\n"
159 ++ "type does not match how it is used elsewhere."
159 ++ "type does not match how it is used elsewhere."
160+ , Nothing
160 )
161 )
161
162
162 BinopLeft op region ->
163 BinopLeft op region ->
163 ( Just region
164 ( Just region
164 , "The left argument of " ++ prettyOperator op ++ " is causing a type mismatch."
165 , "The left argument of " ++ prettyOperator op ++ " is causing a type mismatch."
166+ , Nothing
165 )
167 )
166
168
167 BinopRight op region ->
169 BinopRight op region ->
168 ( Just region
170 ( Just region
169 , "The right argument of " ++ prettyOperator op ++ " is causing a type mismatch."
171 , "The right argument of " ++ prettyOperator op ++ " is causing a type mismatch."
172+ , Nothing
170 )
173 )
171
174
172 Binop op ->
175 Binop op ->
173 ( Nothing
176 ( Nothing
174 , "The two arguments to " ++ prettyOperator op ++ " are fine, but the overall type of this expression\n"
177 , "The two arguments to " ++ prettyOperator op ++ " are fine, but the overall type of this expression\n"
175 ++ "does not match how it is used elsewhere."
178 ++ "does not match how it is used elsewhere."
179+ , Nothing
176 )
180 )
177
181
178 Function maybeName ->
182 Function maybeName ->
179 ( Nothing
183 ( Nothing
180 , "The return type of " ++ funcName maybeName ++ " is being used in unexpected ways."
184 , "The return type of " ++ funcName maybeName ++ " is being used in unexpected ways."
185+ , Nothing
181 )
186 )
182
187
183 UnexpectedArg maybeName index region ->
188 UnexpectedArg maybeName index region ->
184 ( Just region
189 ( Just region
185 , "The " ++ ordinalize index ++ " argument to " ++ funcName maybeName
190 , "The " ++ ordinalize index ++ " argument to " ++ funcName maybeName
186 ++ " has an unexpected type."
191 ++ " has an unexpected type."
192+ , Nothing
187 )
193 )
188
194
189 FunctionArity maybeName expected actual region ->
195 FunctionArity maybeName expected actual region ->
@@ -193,21 +199,25 @@ hintToString hint =
193 ( Just region
199 ( Just region
194 , capitalize (funcName maybeName) ++ " is expecting " ++ show expected
200 , capitalize (funcName maybeName) ++ " is expecting " ++ show expected
195 ++ " argument" ++ s ++ ", but was given " ++ show actual ++ "."
201 ++ " argument" ++ s ++ ", but was given " ++ show actual ++ "."
202+ , Nothing
196 )
203 )
197
204
198 BadTypeAnnotation name ->
205 BadTypeAnnotation name ->
199 ( Nothing
206 ( Nothing
200 , "The type annotation for `" ++ name ++ "` does not match its definition."
207 , "The type annotation for `" ++ name ++ "` does not match its definition."
208+ , Nothing
201 )
209 )
202
210
203 Instance name ->
211 Instance name ->
204 ( Nothing
212 ( Nothing
205 , "Given how `" ++ name ++ "` is defined, this use will not work out."
213 , "Given how `" ++ name ++ "` is defined, this use will not work out."
214+ , Nothing
206 )
215 )
207
216
208 Literal name ->
217 Literal name ->
209 ( Nothing
218 ( Nothing
210 , "This " ++ name ++ " value is being used as if it is some other type of value."
219 , "This " ++ name ++ " value is being used as if it is some other type of value."
220+ , Nothing
211 )
221 )
212
222
213 Pattern patErr ->
223 Pattern patErr ->
@@ -221,26 +231,31 @@ hintToString hint =
221 in
231 in
222 ( Nothing
232 ( Nothing
223 , "Problem with " ++ thing ++ " in this pattern match."
233 , "Problem with " ++ thing ++ " in this pattern match."
234+ , Nothing
224 )
235 )
225
236
226 Shader ->
237 Shader ->
227 ( Nothing
238 ( Nothing
228 , "There is some problem with this GLSL shader."
239 , "There is some problem with this GLSL shader."
240+ , Nothing
229 )
241 )
230
242
231 Range ->
243 Range ->
232 ( Nothing
244 ( Nothing
233− , "The low and high members of this list range do not match."
245+ , "The low and high members of this list range are not the same type of value."
246+ , Nothing
234 )
247 )
235
248
236 Lambda ->
249 Lambda ->
237 ( Nothing
250 ( Nothing
238 , "This anonymous function is being used in an unexpected way."
251 , "This anonymous function is being used in an unexpected way."
252+ , Nothing
239 )
253 )
240
254
241 Record ->
255 Record ->
242 ( Nothing
256 ( Nothing
243 , "This record is being used in an unexpected way."
257 , "This record is being used in an unexpected way."
258+ , Nothing
244 )
259 )
245
260
246
261