mirror of
https://github.com/Mercury-Language/mercury.git
synced 2026-04-16 18:03:36 +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.
120 lines
3.8 KiB
Mathematica
120 lines
3.8 KiB
Mathematica
%-----------------------------------------------------------------------------%
|
|
% vim: ft=mercury ts=4 sw=4 et wm=0 tw=0
|
|
%-----------------------------------------------------------------------------%
|
|
% Copyright (C) 1998, 2006 The University of Melbourne.
|
|
% This file may only be copied under the terms of the GNU General
|
|
% Public License - see the file COPYING in the Mercury distribution.
|
|
%-----------------------------------------------------------------------------%
|
|
%
|
|
% Main author: bromage
|
|
%
|
|
% This module contains code to filter the diff before output, based on
|
|
% the command-line options presented.
|
|
%
|
|
% At the moment, only one option is handled: --ignore-blank-lines.
|
|
% This causes edits to be dropped if they contain changes which only
|
|
% add, delete or change blank lines.
|
|
%
|
|
% TO DO: What exactly is a blank line, and does its definition change
|
|
% if --ignore-space-change or --ignore-all-space have been specified?
|
|
% At the moment, we define a blank line to be a line containing zero or more
|
|
% whitespace characters. Check if this is correct or not.
|
|
%
|
|
%-----------------------------------------------------------------------------%
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
:- module filter.
|
|
:- interface.
|
|
|
|
:- import_module difftype.
|
|
:- import_module file.
|
|
|
|
:- import_module io.
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
:- pred filter_diff(file::in, file::in, diff::in, diff::out,
|
|
io::di, io::uo) is det.
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
:- implementation.
|
|
|
|
:- import_module globals.
|
|
:- import_module options.
|
|
|
|
:- import_module bool.
|
|
:- import_module char.
|
|
:- import_module int.
|
|
:- import_module list.
|
|
:- import_module pair.
|
|
:- import_module string.
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
filter_diff(File1, File2, !Diff, !IO) :-
|
|
globals.io_lookup_bool_option(ignore_blank_lines, FilterBlank, !IO),
|
|
(
|
|
% If we didn't request a filter, skip this pass.
|
|
FilterBlank = no
|
|
;
|
|
FilterBlank = yes,
|
|
filter.blank_lines(!.Diff, File1, File2, !:Diff)
|
|
).
|
|
|
|
:- pred filter.blank_lines(diff::in, file::in, file::in, diff::out) is det.
|
|
|
|
filter.blank_lines([], _, _, []).
|
|
filter.blank_lines([Edit | Diff0], File1, File2, Diff) :-
|
|
filter.blank_lines(Diff0, File1, File2, Diff1),
|
|
(
|
|
Edit = add(_, Y1 - Y2),
|
|
( if range_has_only_blank_lines(Y1, Y2, File2) then
|
|
Diff = Diff1
|
|
else
|
|
Diff = [Edit | Diff1]
|
|
)
|
|
;
|
|
Edit = delete(X1 - X2, _),
|
|
( if range_has_only_blank_lines(X1, X2, File1) then
|
|
Diff = Diff1
|
|
else
|
|
Diff = [Edit | Diff1]
|
|
)
|
|
;
|
|
Edit = change(X1 - X2, Y1 - Y2),
|
|
( if
|
|
range_has_only_blank_lines(X1, X2, File1),
|
|
range_has_only_blank_lines(Y1, Y2, File2)
|
|
then
|
|
Diff = Diff1
|
|
else
|
|
Diff = [Edit | Diff1]
|
|
)
|
|
).
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
:- pred range_has_only_blank_lines(int::in, int::in, file::in) is semidet.
|
|
|
|
range_has_only_blank_lines(First, Last, File) :-
|
|
(
|
|
First < Last
|
|
=>
|
|
(
|
|
file.get_line(File, First, Line),
|
|
string.to_char_list(Line, Chars),
|
|
all [C] (
|
|
list.member(C, Chars)
|
|
=>
|
|
char.is_whitespace(C)
|
|
),
|
|
range_has_only_blank_lines(First + 1, Last, File)
|
|
)
|
|
).
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
:- end_module filter.
|
|
%-----------------------------------------------------------------------------%
|