[m-dev.] diff: fix bug with type var error message

Fergus Henderson fjh at cs.mu.OZ.AU
Fri Sep 15 22:24:41 AEDT 2000


Estimated hours taken: 1.5

compiler/prog_io.m:
	Fix a bug: the code to test for type variables having overlapping
	scopes (being both a parameter and also explicitly quantified)
	in type definitions was wrong.  This bug seems to have been caused
	by a cut-and-paste error: the condition used was the same as in
	the immediately following if-then-else.

	Also improve the error message for an existentially quantified
	variable that doesn't occur in the constructor arguments --
	previously we complained "var occurs only in existential
	quantifiers", but if the variable occurs in the constraints,
	then that error message was wrong.  I changed it to say "does
	not occur in arguments of constructor", and to describe the
	entity as a "type variable" rather than just a "var".

tests/invalid/Mmakefile:
tests/invalid/type_vars.m:
tests/invalid/type_vars.err_exp:
	Add a test case to test this code.

Workspace: /home/pgrad/fjh/ws/hg
Index: compiler/prog_io.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/prog_io.m,v
retrieving revision 1.189
diff -u -d -r1.189 prog_io.m
--- compiler/prog_io.m	2000/04/22 07:11:57	1.189
+++ compiler/prog_io.m	2000/09/15 11:02:46
@@ -1433,18 +1433,15 @@
 		;
 			list__member(Ctor, Constrs),
 			Ctor = ctor(ExistQVars, _Constraints, _CtorName,
-					CtorArgs),
+					_CtorArgs),
 			list__member(Var, ExistQVars),
-			assoc_list__values(CtorArgs, CtorArgTypes),
-			\+ term__contains_var_list(CtorArgTypes, Var)
+			term__contains_var_list(Args, Var)
 		->
 			Result = error( "type variable has overlapping scopes (explicit type quantifier shadows argument type)", Body)
 
 		% check that all type variables in existential quantifiers
-		% occur somewhere in the body
-		% (maybe this should just be a warning, not an error?
-		% If we were to allow it, we should at this point delete any
-		% such unused type variables from the list of quantifiers.)
+		% occur somewhere in the constructor argument types
+		% (not just the constraints)
 		;
 			list__member(Ctor, Constrs),
 			Ctor = ctor(ExistQVars, _Constraints, _CtorName,
@@ -1454,7 +1451,7 @@
 			\+ term__contains_var_list(CtorArgTypes, Var)
 		->
 			Result = error(
-			"var occurs only in existential quantifier",
+		"type variable does not occur in arguments of constructor",
 					Body)
 		% check that all type variables in existential constraints
 		% occur in the existential quantifiers
Index: tests/invalid/Mmakefile
===================================================================
RCS file: /home/mercury1/repository/tests/invalid/Mmakefile,v
retrieving revision 1.66
diff -u -d -r1.66 Mmakefile
--- tests/invalid/Mmakefile	2000/07/24 11:36:17	1.66
+++ tests/invalid/Mmakefile	2000/09/15 11:14:13
@@ -70,6 +70,7 @@
 	type_inf_loop.m \
 	type_loop.m \
 	type_mismatch.m \
+	type_vars.m \
 	typeclass_test_1.m \
 	typeclass_test_2.m \
 	typeclass_test_3.m \
Index: tests/invalid/type_vars.err_exp
===================================================================
RCS file: type_vars.err_exp
diff -N type_vars.err_exp
--- /dev/null	Thu Mar 30 14:06:13 2000
+++ type_vars.err_exp	Fri Sep 15 22:11:08 2000
@@ -0,0 +1,4 @@
+type_vars.m:006: Error: type variable does not occur in arguments of constructor: some [_1, _2] foo(_1) => c(_2).
+type_vars.m:007: Error: type variable does not occur in arguments of constructor: some [_1, _2] bar(_1).
+type_vars.m:008: Error: type variable has overlapping scopes (explicit type quantifier shadows argument type): some [_1] bar(_1).
+For more information, try recompiling with `-E'.
Index: tests/invalid/type_vars.m
===================================================================
RCS file: type_vars.m
diff -N type_vars.m
--- /dev/null	Thu Mar 30 14:06:13 2000
+++ type_vars.m	Fri Sep 15 22:10:49 2000
@@ -0,0 +1,8 @@
+:- module type_vars.
+:- interface.
+
+:- typeclass c(T) where [].
+
+:- type t1 ---> some [T1, T2] foo(T1) => c(T2).
+:- type t2 ---> some [T1, T2] bar(T1).
+:- type t3(T1) ---> some [T1] bar(T1).

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh>  |  of excellence is a lethal habit"
PGP: finger fjh at 128.250.37.3        |     -- the last words of T. S. Garp.
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to:       mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions:          mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------



More information about the developers mailing list