[m-dev.] diff: fix misleading err msg for sub-modules & undef syms

Fergus Henderson fjh at cs.mu.OZ.AU
Tue Mar 14 22:21:05 AEDT 2000


Estimated hours taken: 3

Fix a bug reported by Tyson Dowd <trd at cs.mu.oz.au>
that sometimes resulted in a misleading error messages
for undefined symbols in code using sub-modules.

compiler/make_hlds.m:
	Fix a bug: replace an incorrect hard-coded test
	with a call to status_defined_in_this_module.
	Without this fix, it was failing to calculate the
	imported_modules field in the module_info
	correctly for modules containg sub-modules.

compiler/typecheck.m:
	When checking to see whether a module qualifier
	is visible, use match_sym_name/2 to see whether
	it matches any of the visible module names, so
	that e.g. `foo' will match `parent:foo'.

tests/invalid/Mmakefile:
tests/invalid/undef_mod_qual.m:
tests/invalid/undef_mod_qual.err_exp:
	A regression test.

Workspace: /d-drive/home/hg/fjh/mercury
Index: compiler/make_hlds.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/make_hlds.m,v
retrieving revision 1.325
diff -u -d -r1.325 make_hlds.m
--- compiler/make_hlds.m	2000/03/13 02:23:00	1.325
+++ compiler/make_hlds.m	2000/03/14 10:43:57
@@ -231,7 +231,7 @@
 	; { ModuleDefn = import(module(Specifiers)) } ->
 		{ Status = Status0 },
 		{ Status = item_status(IStat, _) },
-		( { IStat = local ; IStat = exported } ->
+		( { status_defined_in_this_module(IStat, yes) } ->
 			{ module_add_imported_module_specifiers(Specifiers,
 				Module0, Module) }
 		;
@@ -240,7 +240,7 @@
 	; { ModuleDefn = use(module(Specifiers)) } ->
 		{ Status = Status0 },
 		{ Status = item_status(IStat, _) },
-		( { IStat = local ; IStat = exported } ->
+		( { status_defined_in_this_module(IStat, yes) } ->
 			{ module_add_imported_module_specifiers(Specifiers,
 				Module0, Module) }
 		;
Index: compiler/typecheck.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/typecheck.m,v
retrieving revision 1.272
diff -u -d -r1.272 typecheck.m
--- compiler/typecheck.m	2000/02/15 00:34:56	1.272
+++ compiler/typecheck.m	2000/03/14 10:59:30
@@ -5367,16 +5367,14 @@
 
 maybe_report_missing_import(TypeCheckInfo, ModuleQualifier) -->
 	{ typecheck_info_get_module_info(TypeCheckInfo, ModuleInfo) },
-	{ module_info_name(ModuleInfo, ThisModule) },
-	{ module_info_get_imported_module_specifiers(ModuleInfo,
-		ImportedModules) },
 	(
-		% the visible modules are the current module, any
-		% imported modules, and any ancestor modules.
-		{ ModuleQualifier \= ThisModule },
-		{ \+ set__member(ModuleQualifier, ImportedModules) },
-		{ get_ancestors(ThisModule, ParentModules) },
-		{ \+ list__member(ModuleQualifier, ParentModules) }
+		% if the module qualifier couldn't match any of the
+		% visible modules, then we report that the module
+		% has not been imported
+		\+ (
+			{ visible_module(VisibleModule, ModuleInfo) },
+			{ match_sym_name(ModuleQualifier, VisibleModule) }
+		)
 	->
 		io__write_string("\n"),
 		{ typecheck_info_get_context(TypeCheckInfo, Context) },
@@ -5386,6 +5384,25 @@
 		io__write_string("' has not been imported).\n")
 	;
 		io__write_string(".\n")
+	).
+
+:- pred visible_module(module_name, module_info).
+:- mode visible_module(out, in) is multi.
+
+visible_module(VisibleModule, ModuleInfo) :-
+	module_info_name(ModuleInfo, ThisModule),
+	module_info_get_imported_module_specifiers(ModuleInfo, ImportedModules),
+	%
+	% the visible modules are the current module, any
+	% imported modules, and any ancestor modules.
+	%
+	(
+		VisibleModule = ThisModule
+	;
+		set__member(VisibleModule, ImportedModules)
+	;
+		get_ancestors(ThisModule, ParentModules),
+		list__member(VisibleModule, ParentModules)
 	).
 
 :- pred report_error_func_instead_of_pred(typecheck_info, pred_or_func,
Index: tests/invalid/Mmakefile
===================================================================
RCS file: /home/mercury1/repository/tests/invalid/Mmakefile,v
retrieving revision 1.57
diff -u -d -r1.57 Mmakefile
--- tests/invalid/Mmakefile	2000/01/13 06:19:33	1.57
+++ tests/invalid/Mmakefile	2000/03/14 10:59:53
@@ -72,6 +72,7 @@
 	unbound_inst_var.m \
 	undef_lambda_mode.m \
 	undef_mode.m \
+	undef_mod_qual.m \
 	undef_symbol.m \
 	undef_type.m \
 	unify_mode_error.m \
cvs diff: tests/invalid/undef_mod_qual.err_exp is a new entry, no comparison available
cvs diff: tests/invalid/undef_mod_qual.m is a new entry, no comparison available

====================
tests/invalid/undef_mod_qual.err_exp
====================
undef_mod_qual.m:012: In clause for predicate `undef_mod_qual:main/2':
undef_mod_qual.m:012:   error: undefined predicate `foo:bletchx/2'.
For more information, try recompiling with `-E'.
====================
tests/invalid/undef_mod_qual.m
====================

:- module undef_mod_qual.

:- interface.
:- import_module io.
:- pred main(io__state::di, io__state::uo) is det.

:- implementation.
:- use_module undef_mod_qual__foo.

main -->
	foo__bletchx.

%-------------------------------------------------------------------------
% foo is a submodule

:- module foo.

:- interface.
:- pred bletch(io__state::di, io__state::uo) is det.

:- implementation.
bletch -->
	write_string("Hi There").

:- end_module foo.


:- end_module undef_mod_qual.


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