[m-dev.] diff: bug fix for typeclass w/ multi moded method

David Glen JEFFERY dgj at cs.mu.OZ.AU
Wed Sep 29 15:19:10 AEST 1999


Estimated hours taken: 1

Fix a spurious error when there is a typeclass method with multiple modes.

compiler/check_typeclass.m:
	Compare the number of generated procedures with the number of methods in
	the typeclass, not the instance declarations since the typeclass has
	one per proc put the instance has one per pred.
tests/hard_coded/typeclasses/multi_moded.{m,exp}:
	A test case for this.
tests/hard_coded/typeclasses/Mmakefile:
	Turn this test case on.

Index: check_typeclass.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/compiler/check_typeclass.m,v
retrieving revision 1.26
diff -u -t -r1.26 check_typeclass.m
--- check_typeclass.m	1999/07/14 14:56:10	1.26
+++ check_typeclass.m	1999/09/28 06:35:39
@@ -146,7 +146,7 @@
                 ModuleInfo1 = ModuleInfo0,
                 Errors2 = Errors0
         ;
-                InstanceBody = concrete(Methods),
+                InstanceBody = concrete(_Methods),
                 list__foldl2(
                         check_instance_pred(ClassId, Vars, ClassInterface), 
                         PredIds, InstanceDefn0, InstanceDefn1,
@@ -178,7 +178,7 @@
                                 _, MaybePredProcs, _, _),
                 (
                         MaybePredProcs = yes(PredProcs),
-                        list__same_length(PredProcs, Methods)
+                        list__same_length(PredProcs, ClassInterface)
                 ->
                         Errors2 = Errors1
                 ;

cvs diff: Diffing .
Index: Mmakefile
===================================================================
RCS file: /home/staff/zs/imp/tests/hard_coded/typeclasses/Mmakefile,v
retrieving revision 1.20
diff -u -t -r1.20 Mmakefile
--- Mmakefile	1999/09/13 10:14:49	1.20
+++ Mmakefile	1999/09/29 05:07:05
@@ -24,6 +24,7 @@
         mode_decl_order_bug \
         multi_constraint_diff_tvar \
         multi_constraint_same_tvar \
+        multi_moded \
         multi_parameter \
         nondet_class_method \
         operator_classname \
cvs diff: multi_moded.exp is a new entry, no comparison available
cvs diff: multi_moded.m is a new entry, no comparison available
===================================================================
multi_moded.m:
===================================================================

:- module multi_moded.

:- interface.

:- import_module io.

:- pred main(io__state::di, io__state::uo) is det.

:- implementation.

:- import_module std_util.

:- typeclass thisclass(T) where [
	pred c(T, T),
	mode c(in, in) is semidet,
	mode c(out, in) is semidet,
	mode c(in, out) is nondet
].

:- instance thisclass(int) where [
	pred(c/2) is p
].

:- pred p(int, int).
:- mode p(in, in) is semidet.
:- mode p(out, in) is semidet.
:- mode p(in, out) is nondet.
p(1, 1).
p(1, 2).
p(1, 3).
p(2, 4).

:- pred mypred(T, T) <= thisclass(T).
:- mode mypred(in, out) is nondet.
mypred(A, B) :- c(A, B).

main -->
	{ solutions(mypred(1), X) },
	io__write(X),
	nl.

===================================================================
===================================================================
multi_moded.exp:
===================================================================
[1, 2, 3]
===================================================================

dgj
-- 
David Jeffery (dgj at cs.mu.oz.au) | If your thesis is utterly vacuous
PhD student,                    | Use first-order predicate calculus.
Dept. of Comp. Sci. & Soft. Eng.|     With sufficient formality
The University of Melbourne     |     The sheerist banality
Australia                       | Will be hailed by the critics: "Miraculous!"
                                |     -- Anon.
--------------------------------------------------------------------------
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