comparison src/elab_err.sml @ 1584:c37d8341940a

Shorter, more focused error messages about undetermined unification variables
author Adam Chlipala <adam@chlipala.net>
date Sat, 29 Oct 2011 17:30:34 -0400
parents dfb38a333816
children 6c00d8af6239
comparison
equal deleted inserted replaced
1583:7fcdf836b761 1584:c37d8341940a
260 | Nonpositive of decl 260 | Nonpositive of decl
261 261
262 fun lspan [] = ErrorMsg.dummySpan 262 fun lspan [] = ErrorMsg.dummySpan
263 | lspan ((_, loc) :: _) = loc 263 | lspan ((_, loc) :: _) = loc
264 264
265 val p_decl = P.p_decl 265 val baseLen = 2000
266
267 fun p_decl env d =
268 let
269 val fname = OS.FileSys.tmpName ()
270 val out' = TextIO.openOut fname
271 val out = Print.openOut {dst = out', wid = 80}
272
273 fun readFromFile () =
274 let
275 val inf = TextIO.openIn fname
276
277 fun loop acc =
278 case TextIO.inputLine inf of
279 NONE => String.concat (rev acc)
280 | SOME line => loop (line :: acc)
281 in
282 loop []
283 before TextIO.closeIn inf
284 end
285 in
286 Print.fprint out (P.p_decl env d);
287 TextIO.closeOut out';
288 let
289 val content = readFromFile ()
290 in
291 OS.FileSys.remove fname;
292 Print.PD.string (if size content <= baseLen then
293 content
294 else
295 let
296 val (befor, after) = Substring.position "<UNIF:" (Substring.full content)
297 in
298 if Substring.isEmpty after then
299 raise Fail "No unification variables in rendering"
300 else
301 Substring.concat [Substring.full "\n.....\n",
302 if Substring.size befor <= baseLen then
303 befor
304 else
305 Substring.slice (befor, Substring.size befor - baseLen, SOME baseLen),
306 if Substring.size after <= baseLen then
307 after
308 else
309 Substring.slice (after, 0, SOME baseLen),
310 Substring.full "\n.....\n"]
311 end)
312 end
313 end
266 314
267 fun declError env err = 315 fun declError env err =
268 case err of 316 case err of
269 KunifsRemain ds => 317 KunifsRemain ds =>
270 (ErrorMsg.errorAt (lspan ds) "Some kind unification variables are undetermined in declaration\n(look for them as \"<UNIF:...>\")"; 318 (ErrorMsg.errorAt (lspan ds) "Some kind unification variables are undetermined in declaration\n(look for them as \"<UNIF:...>\")";