[m-dev.] diff: fix bug with instance clause module qualification

Fergus Henderson fjh at cs.mu.OZ.AU
Thu Oct 19 05:22:33 AEDT 2000


Estimated hours taken: 0.5

Fix a bug in my recent change to allow typeclass instance declarations
to contain clauses.  The bug was reported by Ralph Becket.

compiler/prog_io_typeclass.m:
	When parsing clauses in instance declarations, don't provide a
	default module name.
	Also, improve the error handling: if parse_item returns an
	error, then propagate that error, rather than discarding it
	and returning a catch-all error.

Workspace: /home/pgrad/fjh/ws/hg
Index: compiler/prog_io_typeclass.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/prog_io_typeclass.m,v
retrieving revision 1.16
diff -u -d -r1.16 prog_io_typeclass.m
--- compiler/prog_io_typeclass.m	2000/09/08 06:02:03	1.16
+++ compiler/prog_io_typeclass.m	2000/10/18 18:06:55
@@ -553,7 +553,7 @@
 		maybe1(instance_method)).
 :- mode term_to_instance_method(in, in, in, out) is det.
 
-term_to_instance_method(ModuleName, VarSet, MethodTerm, Result) :-
+term_to_instance_method(_ModuleName, VarSet, MethodTerm, Result) :-
 	(
 		MethodTerm = term__functor(term__atom("is"), [ClassMethodTerm,
 						InstanceMethod], TermContext)
@@ -618,7 +618,19 @@
 				MethodTerm)
 		)
 	;
-		parse_item(ModuleName, VarSet, MethodTerm, Result0),
+		% For the clauses in an instance declaration,
+		% the default module name for the clause heads
+		% is the module name of the class that this is an
+		% instance declaration for, but we don't necessarily
+		% know what module that is at this point, since the
+		% class name hasn't been fully qualified yet.
+		% So here we give the special module name ""
+		% as the default, which means that there is no default.
+		% (If the module qualifiers in the clauses don't match
+		% the module name of the class, we will pick that up later,
+		% in check_typeclass.m.)
+		DefaultModuleName = unqualified(""),
+		parse_item(DefaultModuleName, VarSet, MethodTerm, Result0),
 		(
 			Result0 = ok(Item, Context),
 			(
@@ -635,10 +647,15 @@
 		->
 			Result = ok(instance_method(PredOrFunc,
 					ClassMethodName,
-					% XXX FIXME handle multiple clauses
 					clauses([Item]),
 					ArityInt, Context))
 		;
+			Result0 = error(ErrorMsg, ErrorTerm)
+		->
+			Result = error(ErrorMsg, ErrorTerm)
+		;
+			% catch-all error message for a syntactically valid item
+			% which is not a clause
 			Result = error("expected clause or `pred(<Name> / <Arity>) is <InstanceName>' or `func(<Name> / <Arity>) is <InstanceName>')",
 				MethodTerm)
 		)

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