diff: add another regression test

Fergus Henderson fjh at cs.mu.OZ.AU
Thu Oct 1 17:41:06 AEST 1998


Estimated hours taken: 0.5

tests/hard_coded/Mmakefile:
tests/hard_coded/var_not_found.m:
tests/hard_coded/var_not_found.exp:
	Add a regression test for a mode analysis bug that resulted
	in a var_not_found error during code generation.
	I don't if the bug was ever fixed, it just happened to
	go away for some unknown reason.

Index: tests/hard_coded/Mmakefile
===================================================================
RCS file: /home/mercury1/repository/tests/hard_coded/Mmakefile,v
retrieving revision 1.42
diff -u -r1.42 Mmakefile
--- Mmakefile	1998/10/01 07:10:09	1.42
+++ Mmakefile	1998/10/01 07:28:07
@@ -87,6 +87,7 @@
 	string_loop \
 	test_imported_no_tag \
 	tim_qual1 \
+	var_not_found \
 	write \
 	write_reg1
 
Index: tests/hard_coded/var_not_found.exp
===================================================================
RCS file: var_not_found.exp
diff -N var_not_found.exp
--- /dev/null	Thu Oct  1 17:39:18 1998
+++ var_not_found.exp	Thu Oct  1 17:28:26 1998
@@ -0,0 +1 @@
+failed (as we should)
Index: tests/hard_coded/var_not_found.m
===================================================================
RCS file: var_not_found.m
diff -N var_not_found.m
--- /dev/null	Thu Oct  1 17:39:18 1998
+++ var_not_found.m	Thu Oct  1 17:37:43 1998
@@ -0,0 +1,56 @@
+%
+% This is a regression test -- previous versions of the Mercury compiler
+% (Oct 98) got a `var not found' error for this test case, due to
+% mode analysis producing incorrect instmap delta annotations
+% for the complicated unification in the implied mode in the
+% first call to map__from_assoc_list in next/3.
+%
+
+:- module var_not_found.
+
+:- interface.
+
+:- import_module io.
+
+:- pred main(io__state::di, io__state::uo) is det.
+
+:- implementation.
+
+:- import_module list, map, std_util.
+:- import_module array, bool, float, int, map, require, std_util, string.
+
+main -->
+	{ map__from_assoc_list([int(1) - int(2)], Map) },
+	( { next(Map, Map, Next) } ->
+		write(Next), nl
+	;
+		write_string("failed (as we should)\n")
+	).
+
+:- type data
+	--->	int(int)
+	;	flt(float)
+	;	str(string)
+	;	array(map(data, data))
+	;	void
+	.
+
+:- pred next(map(data, data), map(data, data), map(data, data)).
+:- mode next(in, in, out) is semidet.
+
+next(Thing, Array, Next) :-
+	map__to_assoc_list(Thing, [int(0) - Key, int(1) - _]),
+	map__to_assoc_list(Array, List),
+	next_pair(List, Key, NewKey - NewValue),
+	map__from_assoc_list([int(0) - NewKey, int(1) - NewValue], Next).
+
+:- pred next_pair(list(pair(data)), data, pair(data)).
+:- mode next_pair(in, in, out) is semidet.
+
+next_pair([Pair0|Pairs], Key, Pair) :-
+	( Pair0 = Key - _ ->
+		Pairs = [Pair|_]
+	;
+		next_pair(Pairs, Key, Pair)
+	).
+

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



More information about the developers mailing list