bug fix for bytecode problem

Fergus Henderson fjh at cs.mu.oz.au
Thu Apr 17 21:06:27 AEST 1997


Estimated hours taken: 3

Fix a bug where bytecode_gen.m was getting a `map__lookup failed' error.
The problem was that typecheck.m was not generating types for variables
that occurred only in quantifiers.

compiler/typecheck.m:
	Ensure that variables in quantifiers are given a type.

Index: typecheck.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/compiler/typecheck.m,v
retrieving revision 1.194
diff -u -r1.194 typecheck.m
--- typecheck.m	1997/04/09 04:56:12	1.194
+++ typecheck.m	1997/04/17 11:05:55
@@ -661,13 +661,15 @@
 	checkpoint("then"),
 	typecheck_goal(B0, B),
 	checkpoint("else"),
-	typecheck_goal(C0, C).
+	typecheck_goal(C0, C),
+	ensure_vars_have_a_type(Vs).
 typecheck_goal_2(not(A0), not(A)) -->
 	checkpoint("not"),
 	typecheck_goal(A0, A).
 typecheck_goal_2(some(Vs, G0), some(Vs, G)) -->
 	checkpoint("some"),
-	typecheck_goal(G0, G).
+	typecheck_goal(G0, G),
+	ensure_vars_have_a_type(Vs).
 typecheck_goal_2(call(_, Mode, Args, Builtin, Context, Name),
 		call(PredId, Mode, Args, Builtin, Context, Name)) -->
 	checkpoint("call"),
@@ -699,6 +701,30 @@
 typecheck_goal_list([Goal0 | Goals0], [Goal | Goals]) -->
 	typecheck_goal(Goal0, Goal),
 	typecheck_goal_list(Goals0, Goals).
+
+%-----------------------------------------------------------------------------%
+
+	% ensure_vars_have_a_type(Vars):
+	%	Ensure that each variable in Vars has been assigned a type.
+
+:- pred ensure_vars_have_a_type(list(var), typecheck_info, typecheck_info).
+:- mode ensure_vars_have_a_type(in, typecheck_info_di, typecheck_info_uo)
+	is det.
+
+ensure_vars_have_a_type(Vars) -->
+	( { Vars = [] } ->
+		[]
+	;
+		% invent some new type variables to use as the types of
+		% these variables
+		{ list__length(Vars, NumVars) },
+		{ varset__init(TypeVarSet0) },
+		{ varset__new_vars(TypeVarSet0, NumVars,
+			TypeVars, TypeVarSet) },
+		{ term__var_list_to_term_list(TypeVars, Types) },
+		typecheck_var_has_polymorphic_type_list(Vars,
+			TypeVarSet, Types)
+	).
 
 %-----------------------------------------------------------------------------%
 

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