[m-dev.] for review: fix undef type error message

David Glen JEFFERY dgj at cs.mu.OZ.AU
Tue Nov 28 12:12:11 AEDT 2000


===================================================================

Estimated hours taken: 1

compiler/module_qual.m:
	When reporting an error about an undefined entity with an explicit
	module qualifier, check that the module in question isn't the
	current module before reporting that it hasn't been imported.

tests/invalid/Mmakefile:
tests/invalid/undef_type_mod_qual.err_exp:
tests/invalid/undef_type_mod_qual.m:
	A test case for this.

===================================================================
Index: compiler/module_qual.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/compiler/module_qual.m,v
retrieving revision 1.62
diff -u -t -r1.62 module_qual.m
--- compiler/module_qual.m	2000/11/17 17:48:13	1.62
+++ compiler/module_qual.m	2000/11/27 05:38:46
@@ -108,7 +108,7 @@
 module_qual__module_qualify_items(Items0, Items, ModuleName, ReportErrors,
                         Info, NumErrors, UndefTypes, UndefModes) -->
         globals__io_get_globals(Globals),
-        { init_mq_info(Items0, Globals, ReportErrors, Info0) },
+        { init_mq_info(Items0, Globals, ReportErrors, ModuleName, Info0) },
         { collect_mq_info(Items0, Info0, Info1) },
         do_module_qualify_items(Items0, Items, Info1, Info),
         { mq_info_get_type_error_flag(Info, UndefTypes) },
@@ -155,6 +155,7 @@
                         bool,   % are there any undefined insts or modes.
                         bool,   % do we want to report errors.
                         error_context,  % context of the current item.
+                        this_module::module_name,  % name of the current module
                         need_qualifier  % must uses of the current item be 
                                 % explicitly module qualified.
         ).
@@ -1208,7 +1209,8 @@
                 %
                 { Id = qualified(ModuleName, _) - _Arity },
                 { mq_info_get_imported_modules(Info, ImportedModules) },
-                { \+ set__member(ModuleName, ImportedModules) }
+                { \+ set__member(ModuleName, ImportedModules) },
+                { \+ ModuleName = Info^this_module }
         ->
                 io__write_string("\n"),
                 prog_out__write_context(Context),
@@ -1393,10 +1395,10 @@
 %-----------------------------------------------------------------------------%
 % Access and initialisation predicates.
 
-:- pred init_mq_info(item_list::in, globals::in, bool::in, mq_info::out)
-        is det.
+:- pred init_mq_info(item_list::in, globals::in, bool::in, module_name::in,
+        mq_info::out) is det.
 
-init_mq_info(Items, Globals, ReportErrors, Info0) :-
+init_mq_info(Items, Globals, ReportErrors, ModuleName, Info0) :-
         term__context_init(Context),
         ErrorContext = type(unqualified("") - 0) - Context,
         set__init(InterfaceModules0),
@@ -1405,7 +1407,8 @@
         id_set_init(Empty),
         Info0 = mq_info(ImportedModules, Empty, Empty, Empty, Empty,
                         Empty, InterfaceModules0, not_exported, 0, no, no,
-                        ReportErrors, ErrorContext, may_be_unqualified).
+                        ReportErrors, ErrorContext, ModuleName,
+                        may_be_unqualified).
 
 :- pred mq_info_get_imported_modules(mq_info::in, set(module_name)::out) is det.
 :- pred mq_info_get_modules(mq_info::in, module_id_set::out) is det.
@@ -1423,26 +1426,26 @@
 :- pred mq_info_get_error_context(mq_info::in, error_context::out) is det.
 
 mq_info_get_imported_modules(mq_info(ImportedModules, _,_,_,_,_,_,_,_,_,_,_,
-        _,_), ImportedModules).
-mq_info_get_modules(mq_info(_, Modules, _,_,_,_,_,_,_,_,_,_,_,_), Modules).
-mq_info_get_types(mq_info(_,_, Types, _,_,_,_,_,_,_,_,_,_,_), Types).
-mq_info_get_insts(mq_info(_,_,_, Insts, _,_,_,_,_,_,_,_,_,_), Insts).
-mq_info_get_modes(mq_info(_,_,_,_, Modes, _,_,_,_,_,_,_,_,_), Modes).
-mq_info_get_classes(mq_info(_,_,_,_,_, Classes, _,_,_,_,_,_,_,_), Classes).
+        _,_,_), ImportedModules).
+mq_info_get_modules(mq_info(_, Modules, _,_,_,_,_,_,_,_,_,_,_,_,_), Modules).
+mq_info_get_types(mq_info(_,_, Types, _,_,_,_,_,_,_,_,_,_,_,_), Types).
+mq_info_get_insts(mq_info(_,_,_, Insts, _,_,_,_,_,_,_,_,_,_,_), Insts).
+mq_info_get_modes(mq_info(_,_,_,_, Modes, _,_,_,_,_,_,_,_,_,_), Modes).
+mq_info_get_classes(mq_info(_,_,_,_,_, Classes, _,_,_,_,_,_,_,_,_), Classes).
 mq_info_get_unused_interface_modules(mq_info(_,_,_,_,_,_, Modules, _,_,_,_,_,
-        _,_), Modules).
-mq_info_get_import_status(mq_info(_,_,_,_,_,_,_, Status, _,_,_,_,_,_), Status).
-mq_info_get_num_errors(mq_info(_,_,_,_,_,_,_,_, NumErrors, _,_,_,_,_),
+        _,_,_), Modules).
+mq_info_get_import_status(mq_info(_,_,_,_,_,_,_, Status,_,_,_,_,_,_,_), Status).
+mq_info_get_num_errors(mq_info(_,_,_,_,_,_,_,_, NumErrors, _,_,_,_,_,_),
         NumErrors).
-mq_info_get_type_error_flag(mq_info(_,_,_,_,_,_,_,_,_, TypeErrs, _,_,_,_),
+mq_info_get_type_error_flag(mq_info(_,_,_,_,_,_,_,_,_, TypeErrs, _,_,_,_,_),
         TypeErrs).
-mq_info_get_mode_error_flag(mq_info(_,_,_,_,_,_,_,_,_,_, ModeError, _,_,_),
+mq_info_get_mode_error_flag(mq_info(_,_,_,_,_,_,_,_,_,_, ModeError, _,_,_,_),
         ModeError).
-mq_info_get_report_error_flag(mq_info(_,_,_,_,_,_,_,_,_,_,_, Report, _,_),
+mq_info_get_report_error_flag(mq_info(_,_,_,_,_,_,_,_,_,_,_, Report, _,_,_),
         Report).
-mq_info_get_error_context(mq_info(_,_,_,_,_,_,_,_,_,_,_,_, Context, _),
+mq_info_get_error_context(mq_info(_,_,_,_,_,_,_,_,_,_,_,_, Context, _,_),
         Context).
-mq_info_get_need_qual_flag(mq_info(_,_,_,_,_,_,_,_,_,_,_,_,_, UseModule),
+mq_info_get_need_qual_flag(mq_info(_,_,_,_,_,_,_,_,_,_,_,_,_,_, UseModule),
         UseModule).
 
 :- pred mq_info_set_imported_modules(mq_info::in, set(module_name)::in,
@@ -1462,37 +1465,37 @@
 :- pred mq_info_set_error_context(mq_info::in, error_context::in,
                                                 mq_info::out) is det.
 
-mq_info_set_imported_modules(mq_info(_, B,C,D,E,F,G,H,I,J,K,L,M,N),
+mq_info_set_imported_modules(mq_info(_, B,C,D,E,F,G,H,I,J,K,L,M,N,O),
                 ImportedModules,
-                mq_info(ImportedModules, B,C,D,E,F,G,H,I,J,K,L,M,N)).
-mq_info_set_modules(mq_info(A, _, C,D,E,F,G,H,I,J,K,L,M,N), Modules,
-                mq_info(A, Modules, C,D,E,F,G,H,I,J,K,L,M,N)).
-mq_info_set_types(mq_info(A,B, _, D,E,F,G,H,I,J,K,L,M,N), Types,
-                mq_info(A,B, Types, D,E,F,G,H,I,J,K,L,M,N)).
-mq_info_set_insts(mq_info(A,B,C, _, E,F,G,H,I,J,K,L,M,N), Insts,
-                mq_info(A,B,C, Insts, E,F,G,H,I,J,K,L,M,N)).
-mq_info_set_modes(mq_info(A,B,C,D, _, F,G,H,I,J,K,L,M,N), Modes,
-                mq_info(A,B,C,D, Modes, F,G,H,I,J,K,L,M,N)).
-mq_info_set_classes(mq_info(A,B,C,D,E, _, G,H,I,J,K,L,M,N), Classes,
-                mq_info(A,B,C,D,E, Classes, G,H,I,J,K,L,M,N)).
-mq_info_set_unused_interface_modules(mq_info(A,B,C,D,E,F, _, H,I,J,K,L,M,N),
+                mq_info(ImportedModules, B,C,D,E,F,G,H,I,J,K,L,M,N,O)).
+mq_info_set_modules(mq_info(A, _, C,D,E,F,G,H,I,J,K,L,M,N,O), Modules,
+                mq_info(A, Modules, C,D,E,F,G,H,I,J,K,L,M,N,O)).
+mq_info_set_types(mq_info(A,B, _, D,E,F,G,H,I,J,K,L,M,N,O), Types,
+                mq_info(A,B, Types, D,E,F,G,H,I,J,K,L,M,N,O)).
+mq_info_set_insts(mq_info(A,B,C, _, E,F,G,H,I,J,K,L,M,N,O), Insts,
+                mq_info(A,B,C, Insts, E,F,G,H,I,J,K,L,M,N,O)).
+mq_info_set_modes(mq_info(A,B,C,D, _, F,G,H,I,J,K,L,M,N,O), Modes,
+                mq_info(A,B,C,D, Modes, F,G,H,I,J,K,L,M,N,O)).
+mq_info_set_classes(mq_info(A,B,C,D,E, _, G,H,I,J,K,L,M,N,O), Classes,
+                mq_info(A,B,C,D,E, Classes, G,H,I,J,K,L,M,N,O)).
+mq_info_set_unused_interface_modules(mq_info(A,B,C,D,E,F, _, H,I,J,K,L,M,N,O),
                 Modules,
-                mq_info(A,B,C,D,E,F, Modules, H,I,J,K,L,M,N)).
-mq_info_set_import_status(mq_info(A,B,C,D,E,F,G, _, I,J,K,L,M,N), Status,
-                mq_info(A,B,C,D,E,F,G, Status, I,J,K,L,M,N)).
-mq_info_set_type_error_flag(mq_info(A,B,C,D,E,F,G,H,I, _, K,L,M,N),
-                mq_info(A,B,C,D,E,F,G,H,I, yes, K,L,M,N)).
-mq_info_set_mode_error_flag(mq_info(A,B,C,D,E,F,G,H,I,J, _, L,M,N),
-                mq_info(A,B,C,D,E,F,G,H,I,J, yes, L,M,N)).
-mq_info_set_error_context(mq_info(A,B,C,D,E,F,G,H,I,J,K,L, _, N), Context,
-                mq_info(A,B,C,D,E,F,G,H,I,J,K,L, Context, N)).
-mq_info_set_need_qual_flag(mq_info(A,B,C,D,E,F,G,H,I,J,K,L,M, _), Flag,
-                mq_info(A,B,C,D,E,F,G,H,I,J,K,L,M, Flag)).
+                mq_info(A,B,C,D,E,F, Modules, H,I,J,K,L,M,N,O)).
+mq_info_set_import_status(mq_info(A,B,C,D,E,F,G, _, I,J,K,L,M,N,O), Status,
+                mq_info(A,B,C,D,E,F,G, Status, I,J,K,L,M,N,O)).
+mq_info_set_type_error_flag(mq_info(A,B,C,D,E,F,G,H,I, _, K,L,M,N,O),
+                mq_info(A,B,C,D,E,F,G,H,I, yes, K,L,M,N,O)).
+mq_info_set_mode_error_flag(mq_info(A,B,C,D,E,F,G,H,I,J, _, L,M,N,O),
+                mq_info(A,B,C,D,E,F,G,H,I,J, yes, L,M,N,O)).
+mq_info_set_error_context(mq_info(A,B,C,D,E,F,G,H,I,J,K,L, _, N,O), Context,
+                mq_info(A,B,C,D,E,F,G,H,I,J,K,L, Context, N,O)).
+mq_info_set_need_qual_flag(mq_info(A,B,C,D,E,F,G,H,I,J,K,L,M,N, _), Flag,
+                mq_info(A,B,C,D,E,F,G,H,I,J,K,L,M,N, Flag)).
 
 :- pred mq_info_incr_errors(mq_info::in, mq_info::out) is det.
 
-mq_info_incr_errors(mq_info(A,B,C,D,E,F,G,H, NumErrors0, J,K,L,M,N), 
-                mq_info(A,B,C,D,E,F,G,H, NumErrors, J,K,L,M,N)) :-
+mq_info_incr_errors(mq_info(A,B,C,D,E,F,G,H, NumErrors0, J,K,L,M,N,O), 
+                mq_info(A,B,C,D,E,F,G,H, NumErrors, J,K,L,M,N,O)) :-
         NumErrors is NumErrors0 + 1.
 
 :- pred mq_info_set_error_flag(mq_info::in, id_type::in, mq_info::out) is det.
Index: tests/invalid/Mmakefile
===================================================================
RCS file: /home/staff/zs/imp/tests/invalid/Mmakefile,v
retrieving revision 1.77
diff -u -t -r1.77 Mmakefile
--- tests/invalid/Mmakefile	2000/11/03 03:12:03	1.77
+++ tests/invalid/Mmakefile	2000/11/28 00:59:15
@@ -97,6 +97,7 @@
         undef_mode_and_no_clauses.m \
         undef_symbol.m \
         undef_type.m \
+        undef_type_mod_qual.m \
         unify_mode_error.m \
         uniq_modes.m \
         uniq_neg.m \

New File: tests/invalid/undef_type_mod_qual.err_exp
===================================================================
undef_type_mod_qual.m:005: In definition of predicate `undef_type_mod_qual:blah'/1:
undef_type_mod_qual.m:005:   error: undefined type `undef_type_mod_qual:undefined_type'/0.
For more information, try recompiling with `-E'.

New File: tests/invalid/undef_type_mod_qual.m
===================================================================
:- module undef_type_mod_qual.
 
:- interface.
 
:- pred blah(undef_type_mod_qual__undefined_type) is det.
 
:- implementation.
 
blah(_).                                                   

-- 
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