[m-rev.] Improved type error message

Ralph Becket rafe at cs.mu.OZ.AU
Thu Feb 7 13:09:13 AEDT 2002


Fergus Henderson, Wednesday,  6 February 2002:
> On 06-Feb-2002, Ralph Becket <rafe at cs.mu.OZ.AU> wrote:
> > compiler/typecheck.m:
> > 	Improved how actual/expected type errors are reported.
> 
> There should be a test case to test your change.

Okay, I'll put that on the to-do list.

> > Index: typecheck.m
> ...
> >  write_var_type_stuff(T, type_stuff(VT, TVarSet, TBinding)) -->
> > +	io__write_string(   "    (actual)   "),
> >  	write_type_b(VT, TVarSet, TBinding),
> > -	io__write_string("/"),
> > +	io__write_string(",\n    (expected) "),
> 
> You should call `prog_out__write_context(Context)'
> at the start of each line of output.
> 
> Also, do you think it would be better to use the word "inferred"
> rather than "actual"?

Here's the relative diff:


diff -u typecheck.m typecheck.m
--- typecheck.m	6 Feb 2002 07:02:06 -0000
+++ typecheck.m	7 Feb 2002 01:09:12 -0000
@@ -5323,7 +5323,6 @@
 		write_argument_name(VarSet, VarId),
 		io__write_string(" has overloaded actual/expected types {\n"),
 
-		prog_out__write_context(Context),
 		write_var_type_stuff_list(TypeStuffList, Type),
 		io__write_string("\n"),
 
@@ -5371,8 +5370,6 @@
 		write_argument_name(VarSet, VarId),
 		io__write_string(" has overloaded actual/expected types {\n"),
 
-		prog_out__write_context(Context),
-		io__write_string("    "),
 		write_arg_type_stuff_list(ArgTypeStuffList),
 		io__write_string("\n"),
 
@@ -5402,35 +5399,41 @@
 write_type_stuff(type_stuff(T, TVarSet, TBinding)) -->
 	write_type_b(T, TVarSet, TBinding).
 
-:- pred write_var_type_stuff_list(list(type_stuff), type, io__state, io__state).
-:- mode write_var_type_stuff_list(in, in, di, uo) is det.
+:- pred write_var_type_stuff_list(prog_context, list(type_stuff), type, io, io).
+:- mode write_var_type_stuff_list(in, in, in, di, uo) is det.
 
-write_var_type_stuff_list(Ts, T) -->
-	io__write_list(Ts, ",\n", write_var_type_stuff(T)).
+write_var_type_stuff_list(Context, Ts, T) -->
+	io__write_list(Ts, ",\n", write_var_type_stuff(Context, T)).
 
-:- pred write_var_type_stuff(type, type_stuff, io__state, io__state).
-:- mode write_var_type_stuff(in, in, di, uo) is det.
+:- pred write_var_type_stuff(prog_context, type, type_stuff, io, io).
+:- mode write_var_type_stuff(in, in, in, di, uo) is det.
 	
-write_var_type_stuff(T, type_stuff(VT, TVarSet, TBinding)) -->
-	io__write_string(   "    (actual)   "),
+write_var_type_stuff(Context, T, type_stuff(VT, TVarSet, TBinding)) -->
+	prog_out__write_context(Context),
+	io__write_string("    (inferred) "),
 	write_type_b(VT, TVarSet, TBinding),
-	io__write_string(",\n    (expected) "),
+	io__write_string(",\n"),
+	prog_out__write_context(Context),
+	io__write_string("    (expected) "),
 	write_type_b(T, TVarSet, TBinding).
 
-:- pred write_arg_type_stuff_list(list(arg_type_stuff), io__state, io__state).
-:- mode write_arg_type_stuff_list(in, di, uo) is det.
+:- pred write_arg_type_stuff_list(prog_context, list(arg_type_stuff), io, io).
+:- mode write_arg_type_stuff_list(in, in, di, uo) is det.
 
-write_arg_type_stuff_list(Ts) -->
-	io__write_list(Ts, ",\n", write_arg_type_stuff).
+write_arg_type_stuff_list(Context, Ts) -->
+	io__write_list(Ts, ",\n", write_arg_type_stuff(Context)).
 
-:- pred write_arg_type_stuff(arg_type_stuff, io__state, io__state).
-:- mode write_arg_type_stuff(in, di, uo) is det.
+:- pred write_arg_type_stuff(prog_context, arg_type_stuff, io, io).
+:- mode write_arg_type_stuff(in, in, di, uo) is det.
 
-write_arg_type_stuff(arg_type_stuff(T0, VT0, TVarSet)) -->
+write_arg_type_stuff(Context, arg_type_stuff(T0, VT0, TVarSet)) -->
+	prog_out__write_context(Context),
 	{ strip_builtin_qualifiers_from_type(VT0, VT) },
-	io__write_string(   "    (actual)   "),
+	io__write_string("    (inferred) "),
 	mercury_output_term(VT, TVarSet, no),
-	io__write_string(",\n    (expected) "),
+	io__write_string(",\n"),
+	prog_out__write_context(Context),
+	io__write_string("    (expected) "),
 	{ strip_builtin_qualifiers_from_type(T0, T) },
 	mercury_output_term(T, TVarSet, no).
 
--------------------------------------------------------------------------
mercury-reviews mailing list
post:  mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the reviews mailing list