diff: fix bug with empty instance definitions

Fergus Henderson fjh at cs.mu.OZ.AU
Mon Feb 15 18:12:53 AEDT 1999


Estimated hours taken: 0.5

Fix a bug with the handling of instance declarations with no methods.

compiler/check_typeclass.m:
	Ensure that the MaybePredProcs field of the HLDS instance definition
	for instance definitions with no methods is set to `yes([])' rather
	than `no' -- the latter would indicate that this pass hasn't been
	run yet.

Index: compiler/check_typeclass.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/check_typeclass.m,v
retrieving revision 1.21
diff -u -r1.21 check_typeclass.m
--- check_typeclass.m	1999/02/12 03:46:52	1.21
+++ check_typeclass.m	1999/02/15 07:06:25
@@ -139,7 +138,7 @@
 	InstanceDefn0 = hlds_instance_defn(_, _, _, _, InstanceBody, _, _, _),
 	(
 		InstanceBody = abstract,
-		InstanceDefn1 = InstanceDefn0,
+		InstanceDefn2 = InstanceDefn0,
 		ModuleInfo1 = ModuleInfo0,
 		Errors2 = Errors0
 	;
@@ -149,12 +148,29 @@
 			PredIds, InstanceDefn0, InstanceDefn1,
 			Errors0 - ModuleInfo0, Errors1 - ModuleInfo1),
 		%
+		% We need to make sure that the MaybePredProcs field is
+		% set to yes(_) after this pass.  Normally that will be
+		% handled by check_instance_pred, but we also need to handle
+		% it below, in case the class has no methods.
+		%
+		InstanceDefn1 = hlds_instance_defn(A, B, C, D, E, 
+				MaybePredProcs1, G, H),
+		(
+			MaybePredProcs1 = yes(_),
+			MaybePredProcs2 = MaybePredProcs1
+		;
+			MaybePredProcs1 = no,
+			MaybePredProcs2 = yes([])
+		),
+		InstanceDefn2 = hlds_instance_defn(A, B, C, D, E, 
+				MaybePredProcs2, G, H),
+		%
 		% Check if there are any instance methods left over,
 		% for which we did not produce a pred_id/proc_id;
 		% if there are any, the instance declaration must have
 		% specified some methods that don't occur in the class.
 		%
-		InstanceDefn1 = hlds_instance_defn(_, Context, _, _,
+		InstanceDefn2 = hlds_instance_defn(_, Context, _, _,
 				_, MaybePredProcs, _, _),
 		(
 			MaybePredProcs = yes(PredProcs),
@@ -178,7 +194,7 @@
 		% check that the superclass constraints are satisfied for the
 		% types in this instance declaration
 	check_superclass_conformance(ClassId, SuperClasses, Vars, ClassVarSet,
-		InstanceDefn1, InstanceDefn,
+		InstanceDefn2, InstanceDefn,
 		Errors2 - ModuleInfo1, Errors - ModuleInfo).
 
 %----------------------------------------------------------------------------%

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "Binaries may die
WWW: <http://www.cs.mu.oz.au/~fjh>  |   but source code lives forever"
PGP: finger fjh at 128.250.37.3        |     -- leaked Microsoft memo.



More information about the developers mailing list