[m-rev.] For review: fix a compiler abort

Ralph Becket rafe at csse.unimelb.edu.au
Wed Nov 28 17:15:43 AEDT 2007

Estimated hours taken: 8
Branches: main

Fix a bug where the compiler was throwing an exception trying to print out some
error messages where the builtin module qualifier had been stripped from the

	In mode_get_insts_semidet/4, if a user-defined mode name is
	unqualified and the lookup fails, qualify the name with
	the mercury_public_builtin_module and try again.

Index: compiler/mode_util.m
RCS file: /home/mercury1/repository/mercury/compiler/mode_util.m,v
retrieving revision 1.200
diff -u -r1.200 mode_util.m
--- compiler/mode_util.m	23 Nov 2007 07:35:15 -0000	1.200
+++ compiler/mode_util.m	28 Nov 2007 05:59:46 -0000
@@ -900,7 +900,15 @@
     list.length(Args, Arity),
     module_info_get_mode_table(ModuleInfo, Modes),
     mode_table_get_mode_defns(Modes, ModeDefns),
-    map.search(ModeDefns, mode_id(Name, Arity), HLDS_Mode),
+    % Try looking up Name as-is.  If that fails and Name is unqualified,
+    % try looking it up with the builtin qualifier.
+    ( if map.search(ModeDefns, mode_id(Name, Arity), HLDS_Mode0) then
+        HLDS_Mode = HLDS_Mode0
+      else
+        Name = unqualified(String),
+        BuiltinName = qualified(mercury_public_builtin_module, String),
+        map.search(ModeDefns, mode_id(BuiltinName, Arity), HLDS_Mode)
+    ),
     HLDS_Mode = hlds_mode_defn(_VarSet, Params, ModeDefn, _Context, _Status),
     ModeDefn = eqv_mode(Mode0),
     mode_substitute_arg_list(Mode0, Params, Args, Mode),
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