mirror of
https://github.com/Mercury-Language/mercury.git
synced 2026-04-15 01:13:30 +00:00
compiler/typecheck_error_undef.m:
When reporting an undefined name/arity pair, if the name happens
to be name of some functions and/or predicates which all have
different arities, add a sentence to the diagnostic to report this fact.
(Normally this happens only when the erroneous code provides
*too many* arguments, because if it does not, then the typechecker
would know that the code can be read as constructing a closure, and
would instead report errors for the arguments that have the wrong type.)
Don't color a closing parenthesis whose open parenthesis
is not colored.
Fix an old bug that we have no test case for: add the missing
initial part of the diagnostic for bugs that report undefined
*non*-user-defined function symbols. There shouldn't be any such
errors, but the types permit it ...
tests/invalid/wrong_arity_function.{m,err_exp}:
Extend this test case to test diagnostic extension described above.
tests/invalid/coerce_syntax.err_exp:
Expect the color change.
50 lines
1.4 KiB
Mathematica
50 lines
1.4 KiB
Mathematica
%---------------------------------------------------------------------------%
|
|
% vim: ts=4 sw=4 et ft=mercury
|
|
%---------------------------------------------------------------------------%
|
|
%
|
|
% When generating an error message for the use of a function symbol with
|
|
% the wrong arity and listing the possible arities, the compiler must report
|
|
% the arities of functions of the same name, as well as the arities of the
|
|
% data constructors of the same name. Prior to 2016 jun 22, it was not
|
|
% not doing that.
|
|
%
|
|
|
|
:- module wrong_arity_function.
|
|
:- interface.
|
|
|
|
:- import_module io.
|
|
|
|
:- pred main(io::di, io::uo) is det.
|
|
|
|
:- implementation.
|
|
|
|
:- import_module int.
|
|
:- import_module list.
|
|
:- import_module string.
|
|
|
|
main(!IO) :-
|
|
% The message for this error should include
|
|
% - the arity 1 data constructor "f" in string.poly_type, and
|
|
% - the arity 2 function "f" defined below
|
|
% in the main part, and
|
|
% - the arity 2 function "f" defined below,
|
|
% - the arity 3 predicate "f" defined below, and
|
|
% - the arity 4 predicate "f" defined below
|
|
% in the "if you are trying to construct a closure" part.
|
|
X = f(1, 2, 3, 4, 5),
|
|
io.format("X = %d\n", [i(X)], !IO).
|
|
|
|
:- func f(int, int) = int.
|
|
|
|
f(A, B) = A + B.
|
|
|
|
:- pred f(int::in, int::in, int::out) is det.
|
|
|
|
f(A, B, AB) :-
|
|
AB = A + B.
|
|
|
|
:- pred f(int::in, int::in, int::in, int::out) is det.
|
|
|
|
f(A, B, C, ABC) :-
|
|
ABC = A + B + C.
|