[m-dev.] for review: fix tuple type printing bug.

Tyson Dowd trd at cs.mu.OZ.AU
Tue Dec 12 18:21:08 AEDT 2000


Hi,

A bug fix.

===================================================================


Estimated hours taken: 0.75

Fix a bug that Simon Mei reported.

When writing the types of tuples, we need to avoid printing an
extra parenthesis (we use braces around tuple types).  For example we
were writing
	{int, int, int)}
instead of
	{int, int, int}

library/std_util.m:
	Reorganize code so that ')' is not added after all type parameter
	lists.

tests/hard_coded/Mmakefile:
tests/hard_coded/write_reg2.exp:
tests/hard_coded/write_reg2.m:
	A regression test for this problem.


Index: library/std_util.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/std_util.m,v
retrieving revision 1.211
diff -u -r1.211 std_util.m
--- library/std_util.m	2000/12/06 12:06:03	1.211
+++ library/std_util.m	2000/12/12 04:15:00
@@ -1513,7 +1513,13 @@
 				UnqualifiedTypeName)
 		;
 			type_arg_names(ArgTypes, IsFunc, ArgTypeNames),
-			string__append_list([Name, "(" | ArgTypeNames],
+			( IsFunc = yes ->
+				list__append(ArgTypeNames, [")"], TypeStrings0)
+			;
+				TypeStrings0 = ArgTypeNames
+			),
+			TypeNameStrings = [Name, "(" | TypeStrings0],
+			string__append_list(TypeNameStrings,
 				UnqualifiedTypeName)
 		)
 	),
@@ -1524,6 +1530,14 @@
 			UnqualifiedTypeName], TypeName)
 	).
 
+
+	% Turn the types into a list of strings representing an argument
+	% list, adding commas as separators as required.  For example:
+	% 	["TypeName1", ",", "TypeName2"]
+	% If formatting a function type, we close the parentheses around
+	% the function's input parameters, e.g.
+	% 	["TypeName1", ",", "TypeName2", ") = ", "ReturnTypeName"]
+	% It is the caller's reponsibility to add matching parentheses.
 :- pred type_arg_names(list(type_desc), bool, list(string)).
 :- mode type_arg_names(in, in, out) is det.
 
@@ -1531,7 +1545,7 @@
 type_arg_names([Type|Types], IsFunc, ArgNames) :-
 	Name = type_name(Type),
 	( Types = [] ->
-		ArgNames = [Name, ")"]
+		ArgNames = [Name]
 	; IsFunc = yes, Types = [FuncReturnType] ->
 		FuncReturnName = type_name(FuncReturnType),
 		ArgNames = [Name, ") = ", FuncReturnName]
Index: tests/hard_coded/Mmakefile
===================================================================
RCS file: /home/mercury1/repository/tests/hard_coded/Mmakefile,v
retrieving revision 1.105
diff -u -r1.105 Mmakefile
--- tests/hard_coded/Mmakefile	2000/12/10 07:39:46	1.105
+++ tests/hard_coded/Mmakefile	2000/12/12 06:31:46
@@ -119,7 +119,8 @@
 	user_defined_equality \
 	user_defined_equality2 \
 	write \
-	write_reg1
+	write_reg1 \
+	write_reg2
 
 # XXX copy_pred does not work in the hl* grades (e.g. hlc.gc),
 # because the MLDS back-end doesn't generate the closure layout
Index: tests/hard_coded/write_reg2.exp
===================================================================
RCS file: write_reg2.exp
diff -N write_reg2.exp
--- /dev/null	Tue Nov 21 11:53:28 2000
+++ write_reg2.exp	Tue Dec 12 17:31:30 2000
@@ -0,0 +1 @@
+univ({1, 2, 3} : {int, int, int})
Index: tests/hard_coded/write_reg2.m
===================================================================
RCS file: write_reg2.m
diff -N write_reg2.m
--- /dev/null	Tue Nov 21 11:53:28 2000
+++ write_reg2.m	Tue Dec 12 17:31:06 2000
@@ -0,0 +1,22 @@
+% Regression test:
+% 
+% This test ensures that tuple types are written out correctly.
+%
+% The Mercury compiler of 12 Dec 2000 failed to correctly
+% run this test.
+% 
+% Author: trd
+
+:- module write_reg2.
+:- interface.
+:- import_module io.
+
+:- pred main(io__state::di, io__state::uo) is det.
+
+:- implementation.
+
+:- import_module std_util.
+
+main -->
+	io__write(univ({1,2,3})),
+	io__nl.


-- 
       Tyson Dowd           # 
                            #  Surreal humour isn't everyone's cup of fur.
     trd at cs.mu.oz.au        # 
http://www.cs.mu.oz.au/~trd #
--------------------------------------------------------------------------
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