[m-dev.] diff: add cyclic_typeclass test case

Fergus Henderson fjh at cs.mu.OZ.AU
Thu Feb 8 23:57:28 AEDT 2001


Estimated hours taken: 0.25

tests/invalid/cyclic_typeclass.m:
	Add a new test case.  This one tests the use of cyclic
	inheritence relationships between type classes.

tests/invalid/Mmakefile:
	Document that we do not yet pass the new test.

Workspace: /home/hg/fjh/mercury
Index: tests/invalid/cyclic_typeclass.m
===================================================================
RCS file: cyclic_typeclass.m
diff -N cyclic_typeclass.m
--- /dev/null	Thu Mar 30 14:06:13 2000
+++ cyclic_typeclass.m	Thu Dec 14 20:31:57 2000
@@ -0,0 +1,44 @@
+/******
+Date: Wed, 1 Dec 1999 22:52:57 +1100
+Subject: compiler infinite loop for cyclic type classes
+
+According to the language reference manual:
+
+|  Typeclass constraints on type class declarations gives rise to a
+|  superclass relation.  This relation must be acyclic.  That is, it is an
+|  error if a type class is its own (direct or indirect) superclass.
+
+But if you try to compile modules containing cyclic typeclasses,
+the compiler goes into an infinite loop and eventually gets a
+stack overflow, rather than reporting a proper error message.
+*****/
+
+:- module cyclic_typeclass.
+
+:- interface.
+
+:- pred main(io__state::di, io__state::uo) is det.
+
+:- import_module io.
+
+:- implementation.
+
+:- typeclass foo(A) <= bar(A) where [
+	func foo(A) = int
+].
+
+:- typeclass bar(A) <= foo(A) where [
+	func bar(A) = int
+].
+
+:- instance foo(int) where [
+	foo(X) = X
+].
+
+:- instance bar(int) where [
+	bar(X) = X
+].
+
+main -->
+	print(foo(42)), nl,
+	print(bar(43)), nl.
Index: tests/invalid/Mmakefile
===================================================================
RCS file: /home/mercury1/repository/tests/invalid/Mmakefile,v
retrieving revision 1.78
diff -u -d -r1.78 Mmakefile
--- tests/invalid/Mmakefile	2001/01/10 02:05:14	1.78
+++ tests/invalid/Mmakefile	2001/01/11 07:46:22
@@ -111,9 +111,9 @@
 #	sub_b.m and sub_c.m (bug with dependencies & nested modules)
 #	freefree.m 	(need bromage's aliasing stuff)
 #	typeclass_test_8.m (minor formatting error in the output --
-#			the type class name should be in quotes;
-#			also a software_error)
+#			the type class name should be in quotes)
 #	typeclass_mode_{2,3,4}.m (compiler calls error/1)
+#	cyclic_typeclass.m (compiler goes into an infinite loop)
 
 MCFLAGS-aditi_errors =		--aditi
 MCFLAGS-aditi_state_errors =	--aditi

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
                                    |  of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh>  |     -- 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