Files
mercury/tests/valid/bug100.m
Julien Fischer f4bf5593f7 Fix bug #100. The compiler is erroneously reporting an import in a module
interface as unused even though the import is required in order to satisfy the
superclass constraints on an exported type class instance.  (The situation
is explained in detail in the diff.)

The fix is to assume that when checking for unused modules, an imported module
that provides a type class instance is used.  We can (and do) avoid this
assumption if the importing module does not export any type class instances
since in that case the erroneous warning cannot occur.

compiler/module_qual.m:
	Keep tracking of which imported modules export type class instances
	and whether the current module exports any.

	Using the above information, avoid incorrectly reporting modules
	imported in the interface as unused if they are in fact required
	because of superclass constraints on instances.
	(This is somewhat inelegant, but alternative fixes would require
	either (a) delaying the unused module check until after the HLDS
	has been constructed, or (b) doing more work on the parse tree
	to make information about type class and instances available.
	Both of these are much larger changes.)

tests/valid/Mercury.options:
tests/valid/Mmakefile:
tests/valid/bug100*.m:
	Regression test for bug 100.

tests/warnings/Mmakefile:
tests/warnings/unused_interface_import*.m:
tests/warnings/unused_interface_import.exp:
	Check that we still emit a warning about unused modules
	that export instances if the module compiled does _not_
	export any instances.
2010-02-02 05:20:27 +00:00

22 lines
451 B
Mathematica

% rotd-2010-01-25 and before were incorrectly reporting that the import
% of the module bug100_2 in the interface was unused.
%
:- module bug100.
:- interface.
:- import_module unit.
:- import_module bug100_3.
% We need this import to get that tc2(unit)
% superclasss constraint is satisfied.
%
:- import_module bug100_2.
:- typeclass tc(T) <= tc2(T) where [].
:- instance tc(unit).
:- implementation.
:- instance tc(unit) where [].