mirror of
https://github.com/Mercury-Language/mercury.git
synced 2026-04-23 21:33:49 +00:00
... effectively replacing part of the functionality of the existing
--warn-singleton-vars option.
compiler/options.m:
doc/user_guide.texi:
Add and document the new option.
compiler/prog_data.m:
doc/reference_manual.texi:
Add and document a new warning name that allows the new option
to be turned off inside a disable_warning scope.
NEWS.md:
Announce the two changes above.
compiler/parse_goal.m:
compiler/parse_tree_out_misc.m:
Parse and unparse the new kind warning in disable_warning scopes.
compiler/make_hlds_warn.m:
We used to avoid traversing the subgoal of a disable_warning scope
if that scope turned off singleton variable warnings. Document why
this is a BUG, and start traversing the scope's subgoal in such cases.
Switch from always constructing error_specs containing conditions
to conditionally constructing error_specs that contain no conditions.
This is required by the change above, because the condition in
conditional error_specs would later be evaluated based on the value
of the specified option in the globals structure, which means that
that test would *ignore* disable_warning scopes. The conditions
under which now construct those error_specs *do* respect those scopes.
Put the enabled/disabled state of each warning into a separate params
structure that, unlike the warn_info structure, contains information
that only ever flows downward, and is never modified except at
disable_warning scopes. Move into this new structure the fields
of the old warn_info structure that share this property.
compiler/add_clause.m:
compiler/simplify_goal_scope.m:
Conform to the changes above.
tests/warnings/repeated_singleton.{m,err_exp}:
A new test case that tests the new option, and the mechanism
for disabling it in a scope.
tests/warnings/Mmakefile:
Enable the new test case.
59 lines
1.6 KiB
Mathematica
59 lines
1.6 KiB
Mathematica
%---------------------------------------------------------------------------%
|
|
% vim: ts=4 sw=4 et ft=mercury
|
|
%---------------------------------------------------------------------------%
|
|
|
|
:- module repeated_singleton.
|
|
:- interface.
|
|
|
|
:- import_module io.
|
|
|
|
:- pred main(io::di, io::uo) is det.
|
|
|
|
:- implementation.
|
|
|
|
:- import_module int.
|
|
:- import_module list.
|
|
:- import_module string.
|
|
|
|
main(!IO) :-
|
|
test_a({1, "foo"}, {2, "bar"}, !IO),
|
|
test_a({1, "foo"}, {2, "foo"}, !IO),
|
|
test_a({11, "foo"}, {2, "bar"}, !IO),
|
|
test_b({1, "foo"}, {2, "bar"}, !IO),
|
|
test_b({1, "foo"}, {2, "foo"}, !IO),
|
|
test_b({11, "foo"}, {2, "bar"}, !IO).
|
|
|
|
:- pred test_a({int, T}::in, {int, T}::in, io::di, io::uo) is det.
|
|
|
|
test_a(A, B, !IO) :-
|
|
( if
|
|
A = {AInt, _AT},
|
|
% This scope should NOT disable the warning for "_AT".
|
|
disable_warning [singleton_vars] ( B = {BInt, _AT} ),
|
|
CInt = AInt + BInt,
|
|
CInt < 10
|
|
then
|
|
AStr = string.string(A),
|
|
BStr = string.string(B),
|
|
io.format("%s %s %d\n", [s(AStr), s(BStr), i(CInt)], !IO)
|
|
else
|
|
io.write_string("failed\n", !IO)
|
|
).
|
|
|
|
:- pred test_b({int, T}::in, {int, T}::in, io::di, io::uo) is det.
|
|
|
|
test_b(A, B, !IO) :-
|
|
( if
|
|
A = {AInt, _AT},
|
|
% This scope SHOULD disable the warning for "_AT".
|
|
disable_warning [repeated_singleton_vars] ( B = {BInt, _AT} ),
|
|
CInt = AInt + BInt,
|
|
CInt < 10
|
|
then
|
|
AStr = string.string(A),
|
|
BStr = string.string(B),
|
|
io.format("%s %s %d\n", [s(AStr), s(BStr), i(CInt)], !IO)
|
|
else
|
|
io.write_string("failed\n", !IO)
|
|
).
|