mirror of
https://github.com/Mercury-Language/mercury.git
synced 2026-04-15 17:33:38 +00:00
compiler/typecheck_errors.m:
When we find a reference to an unknown function symbol/arity pair
but the function symbol itself has definitions with other arities,
we want to print those arities to help programmers diagnose the problem.
When doing this, we used to take into account the arities only of the
data constructor function symbols of the same name; we now also take
into account the arities of the actual functions of the same name.
compiler/hlds_data.m:
Simplify the code for returning the list of the relevant arities
by not filtering out the actual (wrong) arity; this is now done
by the caller in typecheck.m for *both* sources of arities.
tests/invalid/wrong_arity_function.{m,err_exp}:
A test case for this fix.
tests/invalid/Mmakefile:
Enable the new test case.
35 lines
1.0 KiB
Mathematica
35 lines
1.0 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 2 function "f"
|
|
% defined below, as well as the arity 1 data constructor "f" that
|
|
% would wrap a floating point value to be printed in a call to io.format.
|
|
X = f(1, 2, 3),
|
|
io.format("X = %d\n", [i(X)], !IO).
|
|
|
|
:- func f(int, int) = int.
|
|
|
|
f(A, B) = A + B.
|