[m-dev.] diff: detect duplicates in bound inst lists

Fergus Henderson fjh at cs.mu.OZ.AU
Mon Dec 27 22:04:40 AEDT 1999


Estimated hours taken: 0.5

Fix a bug where the compiler was allowing some programs
that it ought to reject.

compiler/prog_io_util.m:
	Ensure that bound inst lists do not specify the
	same functor twice.

tests/invalid/Mmakefile:
tests/invalid/inst_list_dup.m:
tests/invalid/inst_list_dup.err_exp:
	Regression test.

Workspace: /d-drive/home/hg/fjh/mercury
Index: compiler/prog_io_util.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/prog_io_util.m,v
retrieving revision 1.15
diff -u -d -r1.15 prog_io_util.m
--- compiler/prog_io_util.m	1999/07/13 08:53:25	1.15
+++ compiler/prog_io_util.m	1999/12/27 10:48:22
@@ -387,7 +387,14 @@
 parse_bound_inst_list(Disj, Uniqueness, bound(Uniqueness, Functors)) :-
 	disjunction_to_list(Disj, List),
 	convert_bound_inst_list(List, Functors0),
-	list__sort_and_remove_dups(Functors0, Functors).
+	list__sort(Functors0, Functors),
+	% check that the list doesn't specify the same functor twice
+	\+ (
+		list__append(_, SubList, Functors),
+		SubList = [F1, F2 | _],
+		F1 = functor(ConsId, _),
+		F2 = functor(ConsId, _)
+	).
 
 :- pred convert_bound_inst_list(list(term), list(bound_inst)).
 :- mode convert_bound_inst_list(in, out) is semidet.
Index: tests/invalid/Mmakefile
===================================================================
RCS file: /home/mercury1/repository/tests/invalid/Mmakefile,v
retrieving revision 1.55
diff -u -d -r1.55 Mmakefile
--- tests/invalid/Mmakefile	1999/12/10 02:18:09	1.55
+++ tests/invalid/Mmakefile	1999/12/27 10:54:20
@@ -29,6 +29,7 @@
 	ho_type_mode_bug.m \
 	ho_unique_error.m \
 	inline_conflict.m \
+	inst_list_dup.m \
 	io_in_ite_cond.m \
 	missing_det_decls.m \
 	missing_interface_import.m \
Index: tests/invalid/inst_list_dup.err_exp
===================================================================
RCS file: inst_list_dup.err_exp
diff -N inst_list_dup.err_exp
--- /dev/null	Wed May  6 06:32:27 1998
+++ inst_list_dup.err_exp	Mon Dec 27 21:53:52 1999
@@ -0,0 +1,3 @@
+inst_list_dup.m:003: Error: syntax error in inst body: bound((ground - unique ; ground - ground)).
+inst_list_dup.m:  1: Warning: interface for module `inst_list_dup' does not export anything.
+For more information, try recompiling with `-E'.
Index: tests/invalid/inst_list_dup.m
===================================================================
RCS file: inst_list_dup.m
diff -N inst_list_dup.m
--- /dev/null	Wed May  6 06:32:27 1998
+++ inst_list_dup.m	Mon Dec 27 21:53:16 1999
@@ -0,0 +1,3 @@
+:- module inst_list_dup.
+:- interface.
+:- inst inst1 = bound(ground-unique ; ground-ground).

-- 
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