mirror of
https://github.com/Mercury-Language/mercury.git
synced 2025-12-16 06:14:59 +00:00
When a user writes a clause for a predicate (or function) that does not exist
with that arity, but does exist with one or more other arities, report not
just the list of the other arity/arities, but, for each such other arity,
a diff between the declared arg types and the inferred arg types.
After this diff, we generate output like this:
bad_pred_arity.m:027: Error: clause for predicate `bad_pred_arity.p'/4
bad_pred_arity.m:027: without corresponding `:- pred' declaration.
bad_pred_arity.m:027: However, predicates of that name do exist with arities
bad_pred_arity.m:027: 3 and 5.
bad_pred_arity.m:027: Inferred :- pred p(int, string, int, string).
bad_pred_arity.m:027: The argument list difference from the arity 3 version
bad_pred_arity.m:027: is
bad_pred_arity.m:027: pred(
bad_pred_arity.m:027: int,
bad_pred_arity.m:027: + string,
bad_pred_arity.m:027: int,
bad_pred_arity.m:027: string
bad_pred_arity.m:027: )
bad_pred_arity.m:027: The argument list difference from the arity 5 version
bad_pred_arity.m:027: is
bad_pred_arity.m:027: pred(
bad_pred_arity.m:027: int,
bad_pred_arity.m:027: - float,
bad_pred_arity.m:027: string,
bad_pred_arity.m:027: int,
bad_pred_arity.m:027: string
bad_pred_arity.m:027: )
compiler/typecheck_errors.m:
Generate the diff part of the message above.
compiler/typecheck.m:
Invoke typecheck_errors.m when relevant.
compiler/error_util.m:
When comparing two error_specs, switch from a two-level comparison
(first the contexts of error_msgs, then everything else) to three levels
first the contexts of error_msgs, then their error_msg_components,
then everything else). This is needed to allow the error message from
make_hlds_error.m (which reports the error and mentions the arities
with which the named predicate or function does exist) come out before
the informational message from typecheck.m that prints the inferred
arg types and their differences from the other arities. (With the old
comparison, the difference in severity would trump the invisible order
components that this diff includes in both specs to force the desire
order.)
Base the code comparing error_specs on the code for comparing error_msgs.
Move the two previously separate pieces code for those tasks next to each
other.
compiler/make_hlds_error.m:
Add the invisble ordering component.
When we see clauses with two or more wrong arities for a given predicate
or function, don't list the automatically created pred declaration
for an *earlier* wrong-arity clause as a real declaration whose arity
is to be listed in the error messages we generate for *later* wrong-arity
clauses.
Add some documentation.
compiler/add_pred.m:
Factor out some common code.
library/edit_seq.m:
A new module for computing diffs.
library/library.m:
library/MODULES_DOC:
Add the new module to the standard library.
tests/hard_coded/edit_seq_test.{m,exp}:
A new test case for the diff algorithm.
tests/invalid/bad_pred_arity.{m,err_exp}:
A new test case for the new error message.
tests/hard_coded/Mmakefile:
tests/invalid/Mmakefile:
Enable the new test cases.
tests/invalid/bigtest.err_exp:
tests/invalid/bug197.err_exp:
tests/invalid/bug278.err_exp:
tests/invalid/errors2.err_exp:
tests/invalid/invalid_binary_literal.err_exp:
tests/invalid/invalid_float_literal.err_exp:
tests/invalid/invalid_hex_literal.err_exp:
tests/invalid/invalid_main.err_exp:
tests/invalid/invalid_octal_literal.err_exp:
tests/invalid/multimode_dcg.err_exp:
tests/invalid/multisoln_func.err_exp:
tests/invalid/null_char.err_exp:
tests/invalid/state_vars_test3.err_exp:
tests/invalid/try_detism.err_exp2:
tests/invalid/typeclass_test_5.err_exp:
tests/invalid/typeclass_test_8.err_exp:
tests/invalid/unsatisfiable_constraint.err_exp:
tests/invalid_purity/impure_func_t3.err_exp:
Update these files to expect error messages in the new order.
samples/diff/*.m:
Fix comments, mostly by moving them to where our programming style
wants them.
This directory contains some example Mercury programs. hello.m "Hello World" in Mercury. cat.m An implementation of a simple version of the standard UNIX filter `cat', which just copies its input files or the standard input stream to the standard output stream. sort.m An implementation of a simple version of the standard UNIX filter `sort', which reads lines from its input files or the standard input stream, sorts them, and then writes the result to the standard output stream. calculator.m A simple four-function arithmetic calculator, with a parser written using the Definite Clause Grammar notation. calculator2.m A simple four-function arithmetic calculator, which uses the parser module in the standard library with a user-defined operator precedence table. interpreter.m An simple interpreter for definite logic programs. A demonstration of meta-programming in Mercury. expand_terms.m Another example meta-program, showing how to emulate Prolog's `expand_term' mechanism. e.m A small program which calculates the base of natural logarithms to however many digits you choose. It illustrates one way to achieve lazy evaluation in Mercury. Mmakefile The file used by `mmake', the Mercury Make program, to build the programs in this directory. The `solutions' sub-directory contains some examples of the use of nondeterminism, showing how a Mercury program can compute - one solution, - all solutions, or - some solutions (determined by a user-specified criteria) for a query which has more than one logically correct answer. The `concurrency' sub-directory contains examples of how to use Mercury's concurrency interface, i.e. using threads in Mercury programs. There are also some sub-directories which contain examples of multi-module Mercury programs: appengine A simple Google App Engine servlet. diff This directory contains an implementation of a simple version of the standard UNIX utility `diff', which prints the differences between two files. c_interface This directory contains some examples of mixed Mercury/C/C++/Fortran programs using the C interface. java_interface This directory contains some examples of mixed Mercury/Java programs using the foreign language interface. rot13 This directory contains a few implementations of rot-13 encoding. muz This directory contains a syntax checker / type checker for the specification language Z. solver_types This directory contains an example solver type implementation and some sample applications. lazy_list This directory contains an example of the lazy module can be used to implement lazy data structures, in this case a lazy list.