[m-rev.] diff: improve message for mode errores in type calss method implementations

Julien Fischer jfischer at opturion.com
Fri Nov 13 13:39:40 AEDT 2015


Improve message for mode errors in type class method implementations.

compiler/mode_errors.m:
     Don't refer to method wrapper predicates by their internal names
     (i.e. 'ClassMethod_for_ ...) in mode errors.  Instead report the
     method name and identify it as a type class method implementation.

compiler/hlds_error_util.m:
     Don't hardcode the quoting style in a spot.

tests/invalid/bug191.err_exp:
     Conform to the changed error message.

Julien.

diff --git a/compiler/hlds_error_util.m b/compiler/hlds_error_util.m
index 5b7a38c..3638fa8 100644
--- a/compiler/hlds_error_util.m
+++ b/compiler/hlds_error_util.m
@@ -164,7 +164,7 @@ describe_one_pred_info_name(ShouldModuleQualify, PredInfo) = Pieces :-
      else if check_marker(Markers, marker_class_instance_method) then
          Pieces = [words("type class method implementation")]
      else if pred_info_is_promise(PredInfo, PromiseType) then
-        Pieces = [words("`" ++ promise_to_string(PromiseType) ++ "'"),
+        Pieces = [quote(promise_to_string(PromiseType)),
              words("declaration")]
      else
          ( if check_marker(Markers, marker_class_method) then
diff --git a/compiler/mode_errors.m b/compiler/mode_errors.m
index bde9f12..29c4ec8 100644
--- a/compiler/mode_errors.m
+++ b/compiler/mode_errors.m
@@ -1234,22 +1234,29 @@ mode_info_context_preamble(ModeInfo) = Pieces :-
      mode_info_get_proc_id(ModeInfo, ProcId),
      module_info_pred_proc_info(ModuleInfo, PredId, ProcId,
          PredInfo, ProcInfo),
+    pred_info_get_origin(PredInfo, PredOrigin),
+    ( if PredOrigin = origin_instance_method(MethodName, _) then
+        Name0 = unqualify_name(MethodName),
+        ExtraMethodPieces = [words("type class method implementation for")]
+    else
+        Name0 = pred_info_name(PredInfo),
+        ExtraMethodPieces = []
+    ),
      PredOrFunc = pred_info_is_pred_or_func(PredInfo),
+    mode_info_get_instvarset(ModeInfo, InstVarSet),
+    Name = unqualified(Name0),
      pred_info_get_markers(PredInfo, PredMarkers),
      proc_info_declared_argmodes(ProcInfo, Modes0),
      strip_builtin_qualifiers_from_mode_list(Modes0, Modes),
-    Name0 = pred_info_name(PredInfo),
-    Name = unqualified(Name0),
-    mode_info_get_instvarset(ModeInfo, InstVarSet),
      MaybeDet = no,
-
      ModeSubDeclStr = mercury_mode_subdecl_to_string(output_debug, PredOrFunc,
          InstVarSet, Name, Modes, MaybeDet),
-    Pieces1 = [words("In clause for"), words_quote(ModeSubDeclStr),
-        suffix(":"), nl],
      mode_info_get_mode_context(ModeInfo, ModeContext),
-    Pieces2 = mode_context_to_pieces(ModeContext, PredMarkers),
-    Pieces = Pieces1 ++ Pieces2.
+    ModeContextPieces = mode_context_to_pieces(ModeContext, PredMarkers),
+    Pieces = [words("In clause for")] ++
+        ExtraMethodPieces ++
+        [words_quote(ModeSubDeclStr), suffix(":"), nl] ++
+        ModeContextPieces.

  %-----------------------------------------------------------------------------%

diff --git a/tests/invalid/bug191.err_exp b/tests/invalid/bug191.err_exp
index 3caeb3d..491c555 100644
--- a/tests/invalid/bug191.err_exp
+++ b/tests/invalid/bug191.err_exp
@@ -1,6 +1,5 @@
-bug191.m:020: In clause for
-bug191.m:020:   `'ClassMethod_for_bug191__foo____int__arity0______bug191__baz_3'(in,
-bug191.m:020:   in, out((bug191.a)))':
+bug191.m:020: In clause for type class method implementation for `baz(in, in,
+bug191.m:020:   out((bug191.a)))':
  bug191.m:020:   mode error: argument 3 did not get sufficiently instantiated.
  bug191.m:020:   Final instantiatedness of `HeadVar__3' was `ground',
  bug191.m:020:   expected final instantiatedness was `bound(bug191.a(ground))'.



More information about the reviews mailing list