mirror of
https://github.com/Mercury-Language/mercury.git
synced 2026-04-19 03:13:40 +00:00
tests/warnings/*.m:
Bring the programming style of these modules up to date,
except where the problem being tested for seems to be related
to the old programming style
In the infinite_recursion test case, add code that we *should*
warn about, but currently don't.
tests/warnings/*.m:
Update the expected outputs to account for the changes in line
numbers, and the fact that the compiler computes the contexts
of (if C then T else E) if-then-elses differently from (C -> T; E)
if-then-else (it takes the context of the "then" vs the context
of the ";").
Delete arg_order_rearrangment.exp2. It was long unused, but
deleting it in CVS would not have allowed us to put it back later.
55 lines
1.1 KiB
Mathematica
55 lines
1.1 KiB
Mathematica
%---------------------------------------------------------------------------%
|
|
% vim: ts=4 sw=4 et ft=mercury
|
|
%---------------------------------------------------------------------------%
|
|
%
|
|
% Test the warning for infinite recursion.
|
|
%
|
|
%---------------------------------------------------------------------------%
|
|
|
|
:- module infinite_recursion.
|
|
:- interface.
|
|
:- import_module io.
|
|
|
|
:- pred main(io::di, io::uo) is det.
|
|
|
|
:- implementation.
|
|
:- import_module int.
|
|
:- import_module list.
|
|
|
|
main(!IO) :-
|
|
( if
|
|
funny_append([1, 2, 3], [4, 5, 6], Ns),
|
|
sum(Ns, 0, Sum),
|
|
Sum < 42
|
|
then
|
|
main(!IO)
|
|
else
|
|
loop
|
|
).
|
|
|
|
:- pred loop is det.
|
|
|
|
loop :-
|
|
( if semidet_succeed then
|
|
loop
|
|
else
|
|
true
|
|
).
|
|
|
|
:- pred funny_append(list(T)::in, list(T)::in, list(T)::out) is det.
|
|
|
|
funny_append(L1, L2, L3) :-
|
|
(
|
|
L1 = [], L2 = L3
|
|
;
|
|
L1 = [X | _Xs], L3 = [X | Zs],
|
|
funny_append(L1, L2, Zs) % L1 should be _Xs.
|
|
).
|
|
|
|
:- pred sum(list(int)::in, int::in, int::out) is det.
|
|
|
|
sum([], !Sum).
|
|
sum([N | Ns], !Sum) :-
|
|
!:Sum = !.Sum + N,
|
|
sum([N | Ns], !Sum). % [N | Ns] should be N.
|