[m-rev.] diff: improve more error messages

Julien Fischer jfischer at opturion.com
Thu Jul 31 09:01:22 AEST 2014


Branches: master

Improve more error messages.

Make consistency improvements to error messages concerning initialise, finalise
and mutable declarations.

compiler/make_hlds_error.m:
 	Pass a list of format_components to error_if_exported/5 and
 	error_is_exported/4 as the item description instead of a string.

compiler/add_pragma.m:
compiler/make_hlds_passes.m:
 	Conform to the above change.

compiler/modes.m:
 	Use the pragma_decl/1 format component in a couple of spots.

tests/invalid/bad_finalise_decl.err_exp:
tests/invalid/bad_initialise_decl.err_exp:
tests/invalid/bad_mutable.err_exp:
tests/invalid/imported_mode.err_exp:
tests/invalid/not_in_interface.err_exp:
tests/invalid/uniq_mutable.err_exp:
 	Conform to the above changes.

Julien.

diff --git a/compiler/add_pragma.m b/compiler/add_pragma.m
index 754be50..3b90cdd 100644
--- a/compiler/add_pragma.m
+++ b/compiler/add_pragma.m
@@ -108,8 +108,8 @@ add_pass_2_pragma(ItemPragma, !Status, !ModuleInfo, !Specs) :-
          Allowed = no,
          (
              Origin = user,
-            error_if_exported(ImportStatus, Context, "`pragma' declaration",
-                !Specs)
+            error_if_exported(ImportStatus, Context,
+                [decl("pragma"), words("declaration")], !Specs)
          ;
              % We don't report this as an error as it just clutters up
              % the compiler output - the *real* error is whatever caused
diff --git a/compiler/make_hlds_error.m b/compiler/make_hlds_error.m
index b3a5adc..260cabf 100644
--- a/compiler/make_hlds_error.m
+++ b/compiler/make_hlds_error.m
@@ -53,13 +53,13 @@
      % Emit an error if something is exported. (Used to check for
      % when things shouldn't be exported.)
      %
-:- pred error_if_exported(import_status::in, prog_context::in, string::in,
-    list(error_spec)::in, list(error_spec)::out) is det.
+:- pred error_if_exported(import_status::in, prog_context::in,
+    format_components::in, list(error_spec)::in, list(error_spec)::out) is det.

      % Emit an error reporting that something should not have occurred in
      % a module interface.
      %
-:- pred error_is_exported(prog_context::in, string::in,
+:- pred error_is_exported(prog_context::in, format_components::in,
      list(error_spec)::in, list(error_spec)::out) is det.

  %----------------------------------------------------------------------------%
@@ -200,8 +200,9 @@ maybe_undefined_pred_error(Globals, Name, Arity, PredOrFunc, Status,
          !:Specs = [Spec | !.Specs]
      ).

-error_is_exported(Context, Item, !Specs) :-
-    Pieces = [words("Error:"), fixed(Item), words("in module interface."), nl],
+error_is_exported(Context, ItemPieces, !Specs) :-
+    Pieces = [words("Error:")] ++ ItemPieces ++
+        [words("in module interface."), nl],
      Msg = simple_msg(Context, [always(Pieces)]),
      Spec = error_spec(severity_error, phase_parse_tree_to_hlds, [Msg]),
      !:Specs = [Spec | !.Specs].
diff --git a/compiler/make_hlds_passes.m b/compiler/make_hlds_passes.m
index 6dc8f15..2a9fc3d 100644
--- a/compiler/make_hlds_passes.m
+++ b/compiler/make_hlds_passes.m
@@ -1043,7 +1043,8 @@ add_pass_2_initialise(ItemInitialise, Status, !ModuleInfo, !Specs) :-
      ( ImportStatus = status_exported ->
          (
              Origin = user,
-            error_is_exported(Context, "`initialise' declaration", !Specs)
+            error_is_exported(Context,
+                [decl("initialise"), words("declaration")], !Specs)
          ;
              Origin = compiler(Details),
              (
@@ -1077,7 +1078,8 @@ add_pass_2_finalise(ItemFinalise, Status, !ModuleInfo, !Specs) :-
      ( ImportStatus = status_exported ->
          (
              Origin = user,
-            error_is_exported(Context, "`finalise' declaration", !Specs)
+            error_is_exported(Context,
+                [decl("finalise"), words("declaration")], !Specs)
          ;
              % There are no source-to-source transformations that introduce
              % finalise declarations.
@@ -1097,7 +1099,8 @@ add_pass_2_mutable(ItemMutable, Status, !ModuleInfo, !Specs) :-
          MutAttrs, _MutVarset, Context, _SeqNum),
      Status = item_status(ImportStatus, _),
      ( ImportStatus = status_exported ->
-        error_is_exported(Context, "`mutable' declaration", !Specs)
+        error_is_exported(Context,
+            [decl("mutable"), words("declaration")], !Specs)
      ;
          true
      ),
@@ -1187,7 +1190,8 @@ add_pass_2_mutable(ItemMutable, Status, !ModuleInfo, !Specs) :-
              InvalidInstPieces = [
                  words("Error: the inst"),
                  quote(InstStr),
-                words("is not a valid inst for a mutable declaration.")
+                words("is not a valid inst for a"),
+                decl("mutable"), words("declaration.")
              ],
              % XXX We could provide more information about exactly *why* the
              % inst was not valid here as well.
@@ -1329,7 +1333,8 @@ add_pass_3_clause(ItemClause, Status, !ModuleInfo, !QualInfo, !Specs) :-
              UnqualifiedPredName = unqualify_name(PredName),
              ClauseId = simple_call_id_to_string(PredOrFunc,
                  unqualified(UnqualifiedPredName) / Arity),
-            error_is_exported(Context, "clause for " ++ ClauseId, !Specs)
+            error_is_exported(Context, [words("clause for " ++ ClauseId)],
+                !Specs)
          ;
              Origin = compiler(Details),
              (
@@ -1477,8 +1482,9 @@ add_pass_3_initialise(ItemInitialise, Status, !ModuleInfo, !QualInfo,
      (
          PredIds = [],
          Pieces = [words("Error:"), sym_name_and_arity(SymName/Arity),
-            words("used in initialise declaration"),
-            words("does not have a corresponding pred declaration."), nl],
+            words("used in"), decl("initialise"), words("declaration"),
+            words("does not have a corresponding"),
+            decl("pred"), words("declaration."), nl],
          Msg = simple_msg(Context, [always(Pieces)]),
          Spec = error_spec(severity_error, phase_parse_tree_to_hlds, [Msg]),
          !:Specs = [Spec | !.Specs]
@@ -1654,8 +1660,9 @@ add_pass_3_finalise(ItemFinalise, Status, !ModuleInfo, !QualInfo, !Specs) :-
      (
          PredIds = [],
          Pieces = [words("Error:"), sym_name_and_arity(SymName/Arity),
-            words("used in finalise declaration"),
-            words("does not have a corresponding pred declaration."), nl],
+            words("used in"), decl("finalise"), words("declaration"),
+            words("does not have a corresponding"),
+            decl("pred"), words("declaration."), nl],
          Msg = simple_msg(Context, [always(Pieces)]),
          Spec = error_spec(severity_error, phase_parse_tree_to_hlds, [Msg]),
          !:Specs = [Spec | !.Specs]
@@ -1725,8 +1732,8 @@ add_pass_3_finalise(ItemFinalise, Status, !ModuleInfo, !QualInfo, !Specs) :-
                      !ModuleInfo, !QualInfo, !Specs)
              ;
                  Pieces = [words("Error:"), sym_name_and_arity(SymName/Arity),
-                    words("used in finalise declaration"),
-                    words("has invalid signature."), nl],
+                    words("used in"), decl("finalise"),
+                    words("declaration has invalid signature."), nl],
                  Msg = simple_msg(Context, [always(Pieces)]),
                  Spec = error_spec(severity_error, phase_parse_tree_to_hlds,
                      [Msg]),
@@ -1735,8 +1742,9 @@ add_pass_3_finalise(ItemFinalise, Status, !ModuleInfo, !QualInfo, !Specs) :-
          ;
              TailPredIds = [_ | _],
              Pieces = [words("Error:"), sym_name_and_arity(SymName/Arity),
-                words("used in finalise declaration"),
-                words("has multiple pred declarations."), nl],
+                words("used in"), decl("finalise"), words("declaration"),
+                words("has multiple"), decl("pred"), words("declarations."),
+                nl],
              Msg = simple_msg(Context, [always(Pieces)]),
              Spec = error_spec(severity_error, phase_parse_tree_to_hlds, [Msg]),
              !:Specs = [Spec | !.Specs]
diff --git a/compiler/modes.m b/compiler/modes.m
index 19d5697..c8803cc 100644
--- a/compiler/modes.m
+++ b/compiler/modes.m
@@ -1404,7 +1404,7 @@ report_eval_method_requires_ground_args(ProcInfo) = Spec :-
      proc_info_get_context(ProcInfo, Context),
      EvalMethodS = eval_method_to_string(EvalMethod),
      MainPieces = [words("Sorry, not implemented:"),
-        fixed("`pragma " ++ EvalMethodS ++ "'"),
+        pragma_decl(EvalMethodS),
          words("declaration not allowed for procedure"),
          words("with partially instantiated modes."), nl],
      VerbosePieces = [words("Tabling of predicates/functions"),
@@ -1422,7 +1422,7 @@ report_eval_method_destroys_uniqueness(ProcInfo) = Spec :-
      proc_info_get_context(ProcInfo, Context),
      EvalMethodS = eval_method_to_string(EvalMethod),
      MainPieces = [words("Error:"),
-        fixed("`pragma " ++ EvalMethodS ++ "'"),
+        pragma_decl(EvalMethodS),
          words("declaration not allowed for procedure"),
          words("with unique modes."), nl],
      VerbosePieces =
diff --git a/tests/invalid/bad_finalise_decl.err_exp b/tests/invalid/bad_finalise_decl.err_exp
index a4baa2b..626172d 100644
--- a/tests/invalid/bad_finalise_decl.err_exp
+++ b/tests/invalid/bad_finalise_decl.err_exp
@@ -1,10 +1,10 @@
-bad_finalise_decl.m:016: Error: `finalise' declaration in module interface.
-bad_finalise_decl.m:016: Error: `i2'/2 used in finalise declaration has invalid
-bad_finalise_decl.m:016:   signature.
-bad_finalise_decl.m:023: Error: `i1'/2 used in finalise declaration has invalid
-bad_finalise_decl.m:023:   signature.
-bad_finalise_decl.m:024: Error: `i3'/2 used in finalise declaration does not
-bad_finalise_decl.m:024:   have a corresponding pred declaration.
+bad_finalise_decl.m:016: Error: `i2'/2 used in `:- finalise' declaration has
+bad_finalise_decl.m:016:   invalid signature.
+bad_finalise_decl.m:016: Error: `:- finalise' declaration in module interface.
+bad_finalise_decl.m:023: Error: `i1'/2 used in `:- finalise' declaration has
+bad_finalise_decl.m:023:   invalid signature.
+bad_finalise_decl.m:024: Error: `i3'/2 used in `:- finalise' declaration does
+bad_finalise_decl.m:024:   not have a corresponding `:- pred' declaration.
  bad_finalise_decl.m:025: Error: `:- finalise' declaration requires arity, found
  bad_finalise_decl.m:025:   i4.
  bad_finalise_decl.m:026: Error: `:- finalise' declaration specifies a predicate
diff --git a/tests/invalid/bad_initialise_decl.err_exp b/tests/invalid/bad_initialise_decl.err_exp
index 20b5296..c7b3887 100644
--- a/tests/invalid/bad_initialise_decl.err_exp
+++ b/tests/invalid/bad_initialise_decl.err_exp
@@ -1,10 +1,12 @@
-bad_initialise_decl.m:019: Error: `initialise' declaration in module interface.
  bad_initialise_decl.m:019: Error: `i2'/2 used in initialise declaration has
  bad_initialise_decl.m:019:   invalid signature.
+bad_initialise_decl.m:019: Error: `:- initialise' declaration in module
+bad_initialise_decl.m:019:   interface.
  bad_initialise_decl.m:026: Error: `i1'/2 used in initialise declaration has
  bad_initialise_decl.m:026:   invalid signature.
-bad_initialise_decl.m:027: Error: `i3'/2 used in initialise declaration does
-bad_initialise_decl.m:027:   not have a corresponding pred declaration.
+bad_initialise_decl.m:027: Error: `i3'/2 used in `:- initialise' declaration
+bad_initialise_decl.m:027:   does not have a corresponding `:- pred'
+bad_initialise_decl.m:027:   declaration.
  bad_initialise_decl.m:028: Error: `:- initialise' declaration requires arity,
  bad_initialise_decl.m:028:   found i4.
  bad_initialise_decl.m:029: Error: `:- initialise' declaration specifies a
diff --git a/tests/invalid/bad_mutable.err_exp b/tests/invalid/bad_mutable.err_exp
index 394157d..ca47d1f 100644
--- a/tests/invalid/bad_mutable.err_exp
+++ b/tests/invalid/bad_mutable.err_exp
@@ -1,8 +1,8 @@
-bad_mutable.m:005: Error: `mutable' declaration in module interface.
+bad_mutable.m:005: Error: `:- mutable' declaration in module interface.
  bad_mutable.m:011: In declaration for mutable `not_a_type':
  bad_mutable.m:011:   error: undefined type `no_type'/0.
  bad_mutable.m:013: Error: the inst `special_ground' is not a valid inst for a
-bad_mutable.m:013:   mutable declaration.
+bad_mutable.m:013:   `:- mutable' declaration.
  bad_mutable.m:013: In declaration for mutable `not_an_inst':
  bad_mutable.m:013:   error: undefined inst `special_ground'/0.
  bad_mutable.m:015: Error: malformed attribute list in `:- mutable' declaration:
@@ -18,4 +18,4 @@ bad_mutable.m:024:   [thread_local, trailed].
  bad_mutable.m:026: Error: conflicting attributes in attribute list:
  bad_mutable.m:026:   [thread_local, constant].
  bad_mutable.m:031: Error: the inst `bound(f1(ground, unique))' is not a valid
-bad_mutable.m:031:   inst for a mutable declaration.
+bad_mutable.m:031:   inst for a `:- mutable' declaration.
diff --git a/tests/invalid/imported_mode.err_exp b/tests/invalid/imported_mode.err_exp
index a563a39..cd44c2f 100644
--- a/tests/invalid/imported_mode.err_exp
+++ b/tests/invalid/imported_mode.err_exp
@@ -1,4 +1,4 @@
-exported_mode.int:003: Error: mode declaration for predicate
+exported_mode.int:003: Error: `:- mode' declaration for predicate
  exported_mode.int:003:   `exported_mode.p'/2
  exported_mode.int:003:   without preceding `:- pred' declaration.
  exported_mode.int:003: Inferred :- pred p(T1, T2).
diff --git a/tests/invalid/not_in_interface.err_exp b/tests/invalid/not_in_interface.err_exp
index 5d0043a..59185da 100644
--- a/tests/invalid/not_in_interface.err_exp
+++ b/tests/invalid/not_in_interface.err_exp
@@ -1,6 +1,6 @@
-not_in_interface.m:011: Error: `initialise' declaration in module interface.
-not_in_interface.m:013: Error: `mutable' declaration in module interface.
-not_in_interface.m:015: Error: `initialise' declaration in module interface.
-not_in_interface.m:019: Error: `pragma' declaration in module interface.
+not_in_interface.m:011: Error: `:- initialise' declaration in module interface.
+not_in_interface.m:013: Error: `:- mutable' declaration in module interface.
+not_in_interface.m:015: Error: `:- initialise' declaration in module interface.
+not_in_interface.m:019: Error: `:- pragma' declaration in module interface.
  not_in_interface.m:022: Error: clause for predicate `foo'/2 in module
  not_in_interface.m:022:   interface.
diff --git a/tests/invalid/uniq_mutable.err_exp b/tests/invalid/uniq_mutable.err_exp
index 81570dd..9a393c6 100644
--- a/tests/invalid/uniq_mutable.err_exp
+++ b/tests/invalid/uniq_mutable.err_exp
@@ -1,10 +1,10 @@
-uniq_mutable.m:016: Error: the inst `unique' is not a valid inst for a mutable
-uniq_mutable.m:016:   declaration.
+uniq_mutable.m:016: Error: the inst `unique' is not a valid inst for a
+uniq_mutable.m:016:   `:- mutable' declaration.
  uniq_mutable.m:017: Error: the inst `mostly_unique' is not a valid inst for a
-uniq_mutable.m:017:   mutable declaration.
-uniq_mutable.m:018: Error: the inst `free' is not a valid inst for a mutable
-uniq_mutable.m:018:   declaration.
+uniq_mutable.m:017:   `:- mutable' declaration.
+uniq_mutable.m:018: Error: the inst `free' is not a valid inst for a
+uniq_mutable.m:018:   `:- mutable' declaration.
  uniq_mutable.m:019: Error: the inst `clobbered' is not a valid inst for a
-uniq_mutable.m:019:   mutable declaration.
+uniq_mutable.m:019:   `:- mutable' declaration.
  uniq_mutable.m:020: Error: the inst `mostly_clobbered' is not a valid inst for
-uniq_mutable.m:020:   a mutable declaration.
+uniq_mutable.m:020:   a `:- mutable' declaration.



More information about the reviews mailing list