diff: prog_io.m checks for errors in func decls

Fergus Henderson fjh at cs.mu.oz.au
Mon Jul 21 04:05:11 AEST 1997


compiler/prog_io.m:
	Check for some possible errors in function declarations that
	were previously being silently ignored.  Specifically, we
	now catch cases where a function type declaration includes
	modes for some but not all of its arguments or return value,
	or where it includes a determinism but no modes.

Index: prog_io.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/compiler/prog_io.m,v
retrieving revision 1.157
diff -u -r1.157 prog_io.m
--- prog_io.m	1997/07/08 05:49:44	1.157
+++ prog_io.m	1997/07/20 17:57:44
@@ -1088,9 +1088,35 @@
 process_func_2(ok(F, As0), FuncTerm, ReturnTypeTerm, VarSet, MaybeDet, Cond,
 		Result) :-
 	( convert_type_and_mode_list(As0, As) ->
-		( convert_type_and_mode(ReturnTypeTerm, ReturnType) ->
-			Result = ok(func(VarSet, F, As, ReturnType, MaybeDet,
-					Cond))
+		( \+ verify_type_and_mode_list(As) ->
+			Result = error("some but not all arguments have modes",
+					FuncTerm)
+		; convert_type_and_mode(ReturnTypeTerm, ReturnType) ->
+			(
+				As = [type_and_mode(_, _) | _],
+				ReturnType = type_only(_)
+			->
+				Result = error(
+		"function arguments have modes, but function result doesn't",
+					ReturnTypeTerm)
+			;
+				As = [type_only(_) | _],
+				ReturnType = type_and_mode(_, _)
+			->
+				Result = error(
+		"function result has mode, but function arguments don't",
+					ReturnTypeTerm)
+			;
+				ReturnType = type_only,
+				MaybeDet = yes(_)
+			->
+				Result = error(
+"function declaration specifies a determinism but does not specify the mode",
+				FuncTerm)
+			;
+				Result = ok(func(VarSet, F, As, ReturnType,
+					MaybeDet, Cond))
+			)
 		;
 			Result = error(
 			"syntax error in return type of `:- func' declaration",

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