[m-rev.] diff: improve error checking for instance decls
Julien Fischer
juliensf at csse.unimelb.edu.au
Wed Oct 25 18:52:57 AEST 2006
Estimated hours taken: 1
Branches: main, release
Emit an error if abstract instances in the implementation of a module do
not have a corresponding concrete instance.
compiler/check_typeclass.m:
Check that abstract instance declarations in the implementation
section of a module have a corresponding concrete instance
declaration somewhere. Emit an error if they don't.
tests/invalid/missing_concrete_instance.{m,err_exp}:
Extend this test case to cover the above situation.
Julien.
Index: compiler/check_typeclass.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/check_typeclass.m,v
retrieving revision 1.104
diff -u -r1.104 check_typeclass.m
--- compiler/check_typeclass.m 22 Oct 2006 09:14:23 -0000 1.104
+++ compiler/check_typeclass.m 25 Oct 2006 08:47:43 -0000
@@ -891,27 +891,25 @@
%---------------------------------------------------------------------------%
- % Check that every abstract instance in the interface of a module
- % has a corresponding concrete instance in the implementation.
+ % Check that every abstract instance in the module has a
+ % corresponding concrete instance in the implementation.
%
:- pred check_for_missing_concrete_instances(module_info::in, module_info::out,
list(error_spec)::in, list(error_spec)::out) is det.
check_for_missing_concrete_instances(!ModuleInfo, !Specs) :-
module_info_get_instance_table(!.ModuleInfo, InstanceTable),
- % Grab all the abstract instance declarations in the interface of this
- % module and all the concrete instances defined in the implementation.
+ % Grab all the instance declarations that occur in this module
+ % and partition them into two sets: abstract instance declarations
+ % and concrete instance declarations.
gather_abstract_and_concrete_instances(InstanceTable,
AbstractInstances, ConcreteInstances),
map.foldl(check_for_corresponding_instances(ConcreteInstances),
AbstractInstances, !Specs).
- % gather_abstract_and_concrete_instances(Table,
- % AbstractInstances, ConcreteInstances).
- %
% Search the instance_table and create a table of abstract
- % instances that occur in the module interface and a table of
- % concrete instances that occur in the module implementation.
+ % instances that occur in the module and a table of concrete
+ % instances that occur in the module.
% Imported instances are not included at all.
%
:- pred gather_abstract_and_concrete_instances(instance_table::in,
@@ -923,10 +921,8 @@
multi_map.init, Abstracts, multi_map.init, Concretes).
% Partition all the non-imported instances for a particular
- % class into two groups, those that are abstract and in the
- % module interface and those that are concrete and in the module
- % implementation. Concrete instances cannot occur in the
- % interface and we ignore abstract instances in the implementation.
+ % class into two groups, those that are abstract and those that
+ % are concrete.
%
:- pred partition_instances_for_class(class_id::in,
list(hlds_instance_defn)::in, instance_table::in, instance_table::out,
@@ -949,13 +945,7 @@
Body = InstanceDefn ^ instance_body,
(
Body = instance_body_abstract,
- IsExported = status_is_exported_to_non_submodules(ImportStatus),
- (
- IsExported = yes,
- svmulti_map.add(ClassId, InstanceDefn, !Abstracts)
- ;
- IsExported = no
- )
+ svmulti_map.add(ClassId, InstanceDefn, !Abstracts)
;
Body = instance_body_concrete(_),
svmulti_map.add(ClassId, InstanceDefn, !Concretes)
Index: tests/invalid/missing_concrete_instance.err_exp
===================================================================
RCS file: /home/mercury/mercury1/repository/tests/invalid/missing_concrete_instance.err_exp,v
retrieving revision 1.2
diff -u -r1.2 missing_concrete_instance.err_exp
--- tests/invalid/missing_concrete_instance.err_exp 14 Sep 2005 05:26:48 -0000 1.2
+++ tests/invalid/missing_concrete_instance.err_exp 25 Oct 2006 08:44:36 -0000
@@ -2,3 +2,7 @@
missing_concrete_instance.m:011: `missing_concrete_instance.foo(int)' has no
missing_concrete_instance.m:011: corresponding concrete instance in the
missing_concrete_instance.m:011: implementation.
+missing_concrete_instance.m:015: Error: abstract instance declaration for
+missing_concrete_instance.m:015: `missing_concrete_instance.foo(float)' has
+missing_concrete_instance.m:015: no corresponding concrete instance in the
+missing_concrete_instance.m:015: implementation.
Index: tests/invalid/missing_concrete_instance.m
===================================================================
RCS file: /home/mercury/mercury1/repository/tests/invalid/missing_concrete_instance.m,v
retrieving revision 1.1
diff -u -r1.1 missing_concrete_instance.m
--- tests/invalid/missing_concrete_instance.m 13 Apr 2005 07:41:28 -0000 1.1
+++ tests/invalid/missing_concrete_instance.m 25 Oct 2006 08:44:10 -0000
@@ -9,3 +9,7 @@
:- typeclass foo(T) where [].
:- instance foo(int).
+
+:- implementation.
+
+:- instance foo(float).
--------------------------------------------------------------------------
mercury-reviews mailing list
Post messages to: mercury-reviews at csse.unimelb.edu.au
Administrative Queries: owner-mercury-reviews at csse.unimelb.edu.au
Subscriptions: mercury-reviews-request at csse.unimelb.edu.au
--------------------------------------------------------------------------
More information about the reviews
mailing list