[m-rev.] diff: fix error message with incorrect variable names

Julien Fischer juliensf at csse.unimelb.edu.au
Fri Oct 19 13:36:34 AEST 2007


(This is still pending a bootcheck.)

Estimated hours taken: 1
Branches: main

Fix a bug reported by Ondrej Bojar (bug #5 in Mantis) where error
messages concerning unifications involving state variables printed out
the name of the wrong variable.

The problem was that a variable renaming was not being applied as the
parse tree was converted to HLDS.

compiler/add_clause.m:
 	Rename vars in unify_exprs, even in the case where the unify_expr
 	will cause an error to be generated.  If we don't do the renaming
 	the error message may refer to the wrong variable name(s).

tests/invalid/Mmakefile:
tests/invalid/bad_sv_unify_msg.{m,err_exp}:
 	Test case for the above bug.

Julien.

Index: compiler/add_clause.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/add_clause.m,v
retrieving revision 1.45
diff -u -r1.45 add_clause.m
--- compiler/add_clause.m	28 Sep 2007 03:17:11 -0000	1.45
+++ compiler/add_clause.m	19 Oct 2007 03:30:17 -0000
@@ -896,20 +896,20 @@
      ).
  transform_goal_2(unify_expr(A0, B0, Purity), Context, Renaming, Goal,
          NumAdded, !VarSet, !ModuleInfo, !QualInfo, !SInfo, !Specs) :-
+    rename_vars_in_term(need_not_rename, Renaming, A0, A),
+    rename_vars_in_term(need_not_rename, Renaming, B0, B),
      % It is an error for the left or right hand side of a
      % unification to be !X (it may be !.X or !:X, however).
-    ( A0 = functor(atom("!"), [variable(StateVarA, _)], _) ->
+    ( A = functor(atom("!"), [variable(StateVarA, _)], _) ->
          report_svar_unify_error(Context, !.VarSet, StateVarA, !Specs),
          Goal = true_goal,
          NumAdded = 0
-    ; B0 = functor(atom("!"), [variable(StateVarB, _)], _) ->
+    ; B = functor(atom("!"), [variable(StateVarB, _)], _) ->
          report_svar_unify_error(Context, !.VarSet, StateVarB, !Specs),
          Goal = true_goal,
          NumAdded = 0
      ;
          prepare_for_call(!SInfo),
-        rename_vars_in_term(need_not_rename, Renaming, A0, A),
-        rename_vars_in_term(need_not_rename, Renaming, B0, B),
          unravel_unification(A, B, Context, umc_explicit, [], Purity, Goal,
              NumAdded, !VarSet, !ModuleInfo, !QualInfo, !SInfo, !Specs),
          finish_call(!VarSet, !SInfo)
Index: tests/invalid/Mmakefile
===================================================================
RCS file: /home/mercury/mercury1/repository/tests/invalid/Mmakefile,v
retrieving revision 1.222
diff -u -r1.222 Mmakefile
--- tests/invalid/Mmakefile	2 Oct 2007 04:32:50 -0000	1.222
+++ tests/invalid/Mmakefile	19 Oct 2007 03:30:17 -0000
@@ -41,6 +41,7 @@
  	bad_initialise_decl \
  	bad_instance \
  	bad_mutable \
+	bad_sv_unify_msg \
  	bigtest \
  	bind_in_negated \
  	bind_var_errors \
Index: tests/invalid/bad_sv_unify_msg.err_exp
===================================================================
RCS file: tests/invalid/bad_sv_unify_msg.err_exp
diff -N tests/invalid/bad_sv_unify_msg.err_exp
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ tests/invalid/bad_sv_unify_msg.err_exp	19 Oct 2007 03:30:17 -0000
@@ -0,0 +1,18 @@
+bad_sv_unify_msg.m:017:   Error: !D cannot appear as a unification argument.
+bad_sv_unify_msg.m:017:     You probably meant !.D or !:D.
+bad_sv_unify_msg.m:017: In clause for predicate `bad_sv_unify_msg.x'/2:
+bad_sv_unify_msg.m:017:   warning: variable `STATE_VARIABLE_D_1' occurs only
+bad_sv_unify_msg.m:017:   once in this scope.
+bad_sv_unify_msg.m:018: Warning: reference to uninitialized state variable !.D.
+bad_sv_unify_msg.m:011: In predicate `x'/2:
+bad_sv_unify_msg.m:011:   warning: unresolved polymorphism.
+bad_sv_unify_msg.m:011:   The variable with an unbound type was:
+bad_sv_unify_msg.m:011:     STATE_VARIABLE_D_1: T
+bad_sv_unify_msg.m:011:   The unbound type variable will be implicitly bound to
+bad_sv_unify_msg.m:011:   the builtin type `void'.
+bad_sv_unify_msg.m:017: In clause for `x(di, uo)':
+bad_sv_unify_msg.m:017:   in argument 1 of call to predicate `io.write'/3:
+bad_sv_unify_msg.m:017:   mode error: variable `STATE_VARIABLE_D_1' has
+bad_sv_unify_msg.m:017:   instantiatedness `free',
+bad_sv_unify_msg.m:017:   expected instantiatedness was `ground'.
+For more information, recompile with `-E'.
Index: tests/invalid/bad_sv_unify_msg.m
===================================================================
RCS file: tests/invalid/bad_sv_unify_msg.m
diff -N tests/invalid/bad_sv_unify_msg.m
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ tests/invalid/bad_sv_unify_msg.m	19 Oct 2007 03:30:17 -0000
@@ -0,0 +1,19 @@
+% rotd-2007-10-19 and before emitted wrong the variable name in the error
+% message abou !D appear on the LHS of a unification.  The problem was
+% that transform_goal was not applying the variable renaming to the 
+% unification before looking up the variable name.
+%
+:- module bad_sv_unify_msg.
+:- interface.
+
+:- import_module io.
+
+:- pred x(io::di, io::uo) is det.
+
+:- implementation.
+
+x(!IO) :-
+	some [!D] (
+		!D = 3,	% Error message for this refered to the wrong variable.
+		io.write(!.D, !IO)
+	).

--------------------------------------------------------------------------
mercury-reviews mailing list
Post messages to:       mercury-reviews at csse.unimelb.edu.au
Administrative Queries: owner-mercury-reviews at csse.unimelb.edu.au
Subscriptions:          mercury-reviews-request at csse.unimelb.edu.au
--------------------------------------------------------------------------



More information about the reviews mailing list