[m-rev.] diff: fix error message for qualification errors in pragma declarations

Julien Fischer jfischer at opturion.com
Mon Jun 20 21:27:26 AEST 2016


Fix error messages for qualification errors in pragma declarations.

Improve test coverage for qualification errors in pragma declarations.

compiler/module_qual.qual_errors.m:
     The identifying context pieces for qualification errors in pragmas are
 	currently of the form "pragma foo"; change them to the form
 	"`:- pragma foo' declaration" as in the rest of the compiler.

     Fix an error where the names of the tabling pragmas were not being
     used in error messages, the were all being reported as "pragma tabled".

tests/invalid/Mmakefile:
tests/invalid/pragma_qual_error.{m,err_exp}:
     Add further tests for qualification errors in pragmas.

tests/invalid/ee_invalid.err_exp:
tests/invalid/oisu_check_add_pragma_errors.m:
      Conform to the above changes.

Julien.

diff --git a/compiler/module_qual.qual_errors.m b/compiler/module_qual.qual_errors.m
index e26ca40..6edd972 100644
--- a/compiler/module_qual.qual_errors.m
+++ b/compiler/module_qual.qual_errors.m
@@ -537,8 +537,9 @@ mq_error_context_to_pieces(ErrorContext, Context,Pieces) :-
              Pragma = pragma_require_tail_recursion(_),
              PragmaName = "require_tail_recursion"
          ;
-            Pragma = pragma_tabled(_),
-            PragmaName = "tabled"
+            Pragma = pragma_tabled(PragmaInfoTabled),
+            EvalMethod = PragmaInfoTabled ^ tabled_method,
+            PragmaName = eval_method_to_pragma_name(EvalMethod)
          ;
              Pragma = pragma_fact_table(_),
              PragmaName = "fact_table"
@@ -585,7 +586,7 @@ mq_error_context_to_pieces(ErrorContext, Context,Pieces) :-
              Pragma = pragma_require_feature_set(_),
              PragmaName = "require_feature_set"
          ),
-        Pieces = [words("pragma"), words(PragmaName)]
+        Pieces = [pragma_decl(PragmaName), words("declaration")]
      ;
          ErrorContext = mqec_type_qual(Context),
          Pieces = [words("explicit type qualification")]
diff --git a/tests/invalid/Mmakefile b/tests/invalid/Mmakefile
index 1dba876..fcbdcfb 100644
--- a/tests/invalid/Mmakefile
+++ b/tests/invalid/Mmakefile
@@ -337,6 +337,7 @@ C_INTERFACE_MODULES = \
  	fe_unmapped_nonverbose \
  	fe_unmapped_verbose \
  	foreign_decl_line_number \
+	pragma_qual_error \
  	trace_goal_env

  # The following require that the compiler not ignore `pragma type_spec'
diff --git a/tests/invalid/ee_invalid.err_exp b/tests/invalid/ee_invalid.err_exp
index 673ffe3..0569519 100644
--- a/tests/invalid/ee_invalid.err_exp
+++ b/tests/invalid/ee_invalid.err_exp
@@ -1,7 +1,7 @@
  ee_invalid.m:039: In `:- pragma foreign_export_enum' declaration for type
  ee_invalid.m:039:   `int'/0:
  ee_invalid.m:039:   error: `int'/0 is a builtin type.
-ee_invalid.m:043: In pragma foreign_export_enum:
+ee_invalid.m:043: In `:- pragma foreign_export_enum' declaration:
  ee_invalid.m:043:   error: undefined type `undefined_type'/0.
  ee_invalid.m:047: In `:- pragma foreign_export_enum' declaration for type
  ee_invalid.m:047:   `ee_invalid.foo'/1:
diff --git a/tests/invalid/oisu_check_add_pragma_errors.err_exp b/tests/invalid/oisu_check_add_pragma_errors.err_exp
index e8dc8db..0231054 100644
--- a/tests/invalid/oisu_check_add_pragma_errors.err_exp
+++ b/tests/invalid/oisu_check_add_pragma_errors.err_exp
@@ -1,6 +1,6 @@
  oisu_check_add_pragma_errors.m:016: Duplicate `:- pragma oisu' declarations for
  oisu_check_add_pragma_errors.m:016:   `oisu_check_add_pragma_errors.foo'/0.
-oisu_check_add_pragma_errors.m:022: In pragma oisu:
+oisu_check_add_pragma_errors.m:022: In `:- pragma oisu' declaration:
  oisu_check_add_pragma_errors.m:022:   error: undefined type
  oisu_check_add_pragma_errors.m:022:   `oisu_check_add_pragma_errors.quux'/0.
  oisu_check_add_pragma_errors.m:030: `pragma oisu' declarations must always be
diff --git a/tests/invalid/pragma_qual_error.err_exp b/tests/invalid/pragma_qual_error.err_exp
index e69de29..e4c84d1 100644
--- a/tests/invalid/pragma_qual_error.err_exp
+++ b/tests/invalid/pragma_qual_error.err_exp
@@ -0,0 +1,33 @@
+pragma_qual_error.m:025: In `:- pragma foreign_export_enum' declaration:
+pragma_qual_error.m:025:   error: undefined type `bar'/0.
+pragma_qual_error.m:032: In `:- pragma foreign_enum' declaration:
+pragma_qual_error.m:032:   error: undefined type `bar'/0.
+pragma_qual_error.m:039: In `:- pragma reserve_tag' declaration for
+pragma_qual_error.m:039:   `pragma_qual_error.baaz'/0:
+pragma_qual_error.m:039:   error: undefined type `pragma_qual_error.baaz'/0.
+pragma_qual_error.m:046: Error: `:- pragma foreign_proc' declaration for
+pragma_qual_error.m:046:   undeclared mode of predicate
+pragma_qual_error.m:046:   `pragma_qual_error.foo'/2.
+pragma_qual_error.m:046: In `:- pragma foreign_proc' declaration:
+pragma_qual_error.m:046:   error: undefined mode `not_a_mode'/0.
+pragma_qual_error.m:060: Error: `:- pragma memo' declaration for undeclared
+pragma_qual_error.m:060:   mode of predicate `pragma_qual_error.memoproc'/3.
+pragma_qual_error.m:060: In `:- pragma memo' declaration:
+pragma_qual_error.m:060:   error: undefined mode `not_a_mode'/0.
+pragma_qual_error.m:071: Error: `:- pragma loop_check' declaration for
+pragma_qual_error.m:071:   undeclared mode of predicate
+pragma_qual_error.m:071:   `pragma_qual_error.loop_check_proc'/2.
+pragma_qual_error.m:071: In `:- pragma loop_check' declaration:
+pragma_qual_error.m:071:   error: undefined mode `not_a_mode'/0.
+pragma_qual_error.m:088: Error: `:- pragma minimal_model_stack_copy'
+pragma_qual_error.m:088:   declaration for undeclared mode of predicate
+pragma_qual_error.m:088:   `pragma_qual_error.tc'/2.
+pragma_qual_error.m:088: In `:- pragma minimal_model' declaration:
+pragma_qual_error.m:088:   error: undefined mode `not_a_mode'/0.
+pragma_qual_error.m:112: Error: `:- pragma type_spec' declaration for
+pragma_qual_error.m:112:   `pragma_qual_error.type_spec_pred'/2 specifies
+pragma_qual_error.m:112:   non-existent mode.
+pragma_qual_error.m:112: In `:- pragma type_spec' declaration:
+pragma_qual_error.m:112:   error: undefined mode `not_a_mode'/0.
+pragma_qual_error.m:112: In `:- pragma type_spec' declaration:
+pragma_qual_error.m:112:   error: undefined type `not_a_type'/0.
diff --git a/tests/invalid/pragma_qual_error.m b/tests/invalid/pragma_qual_error.m
index e69de29..ba27aa1 100644
--- a/tests/invalid/pragma_qual_error.m
+++ b/tests/invalid/pragma_qual_error.m
@@ -0,0 +1,120 @@
+%---------------------------------------------------------------------------%
+% vim: ft=mercury ts=4 sw=4 et wm=0 tw=0
+%---------------------------------------------------------------------------%
+% Test for error messages produced by module qualification errors in
+% pragma declarations.
+%---------------------------------------------------------------------------%
+
+:- module pragma_qual_error.
+:- interface.
+
+:- type foo ---> foo.
+
+%----------------------------------------------------------------------------%
+%----------------------------------------------------------------------------%
+
+:- implementation.
+
+:- import_module int.
+
+%----------------------------------------------------------------------------%
+%
+% foreign_export_enum.
+%
+
+:- pragma foreign_export_enum("C", bar/0).
+
+%----------------------------------------------------------------------------%
+%
+% foreign_enum.
+%
+
+:- pragma foreign_enum("C", bar/0, [abc - "1"]).
+
+%----------------------------------------------------------------------------%
+%
+% reserve_tag.
+%
+
+:- pragma reserve_tag(baaz/0).
+
+%----------------------------------------------------------------------------%
+%
+% foreign_proc.
+%
+
+:- pragma foreign_proc("C",
+     foo(A::not_a_mode, B::out),
+     [promise_pure, will_not_call_mercury],
+"
+    B = A;
+").
+
+:- pred foo(A::in, B::out) is det.
+
+%----------------------------------------------------------------------------%
+%
+% memo.
+%
+
+:- pragma memo(memoproc(in, in, not_a_mode)).
+
+:- pred memoproc(int::in, int::in, int::out) is det.
+
+memoproc(A, B, A + B).
+
+%----------------------------------------------------------------------------%
+%
+% loop_check.
+%
+
+:- pragma loop_check(loop_check_proc(in, not_a_mode)).
+
+:- pred loop_check_proc(int::in, int::out) is det.
+
+loop_check_proc(N, R) :-
+   ( if N = 0 then
+        R = 1
+   else
+        lookup_check_proc(N - 1, R0),
+        R = 10 * R0
+   ).
+
+%----------------------------------------------------------------------------%
+%
+% minimal_model.
+%
+
+:- pragma minimal_model(tc(in, not_a_mode)).
+
+:- pred tc(int::in, int::out) is nondet.
+
+tc(A, B) :-
+    edge(A, C),
+    (
+        B = C
+    ;
+        tc(C, B)
+    ).
+
+:- pred edge(int::in, int::out) is nondet.
+
+edge(1, 2).
+edge(1, 3).
+edge(2, 1).
+edge(3, 4).
+
+%----------------------------------------------------------------------------%
+%
+% type_spec.
+%
+
+:- pragma type_spec(type_spec_pred(in, not_a_mode), (T = not_a_type)).
+
+:- pred type_spec_pred(T::in, T::out) is det.
+
+type_spec_pred(A, A).
+
+%----------------------------------------------------------------------------%
+:- end_module pragma_qual_error.
+%----------------------------------------------------------------------------%


More information about the reviews mailing list