Files
mercury/tests/valid/instance_superclass.m
Julien Fischer a0e5667af5 Do not allow non-abstract instance declarations to occur in module
For review by anyone.

Estimated hours taken: 10
Branches: main, release

Do not allow non-abstract instance declarations to occur in module
interfaces.  Emit an error message if this occurs.

Fix the formatting of some error messages regarding typeclasses
and instances.

compiler/check_typeclass.m:
	Use error_util to generate the error messages from this module.
	This fixes a problem where the printing of sym_names and arities
	differed in the same error message.

compiler/error_util.m:
	Add a format component for the pred_or_func type.
	Add the equivalence type format_components.

compiler/make_hlds.m:
	Make the format of some error messages concerning typeclasses
	more consistent.

compiler/modules.m:
	Check for non-abstract instance declarations in module interfaces
	and emit an error message if they do.

tests/invalid/Mmakefile:
tests/invalid/instance_bug.m:
tests/invalid/instance_bug.err_exp:
 	Test case for the above.

tests/hard_coded/typeclasses/*:
tests/invalid/*:
tests/recompilation/*:
tests/valid/*:
	Update test cases as necessary.
2005-04-12 07:58:24 +00:00

33 lines
776 B
Mathematica

:- module instance_superclass.
% This is a regression test for the case where there is a superclass
% relationship, and the instance declaration has a type variable in the
% instance type.
:- interface.
:- import_module list.
:- typeclass c1(T) where [ ].
:- typeclass c2(T) <= c1(T) where [ ].
:- instance c1(list(T)).
:- instance c2(list(T)).
:- pred p(T::in) is det.
:- implementation.
:- instance c1(list(T)) where [].
:- instance c2(list(T)) where [].
% The bug that this test case is checking for is at the creation of
% the typeclass info for this call: if the substitution from "T" in
% the typeclass decl to "list(T)" in the instance is applied
% recursively, an infinite loop results.
p(X) :- q([X]).
:- pred q(T) <= c2(T).
:- mode q(in) is det.
q(_).