diff --git a/src/lib/warnings.pl b/src/lib/warnings.pl index ad9bbdab7..afacf3be8 100644 --- a/src/lib/warnings.pl +++ b/src/lib/warnings.pl @@ -48,3 +48,11 @@ unsound_type_test(G), functor(G, F, 1), warn_fail("~q is a constant source of bugs, use ~a_si/1 from library(si)", [F/1,F]). + +% Warn when more than 2 negations are nested. Double negation has legit +% use-case, but I don't think that more nested negations are ever useful. +% +user:goal_expansion(G, _) :- + nonvar(G), + G = (\+ \+ \+ _), + warn_fail("Nested negations can be reduced", []). diff --git a/src/tests/warnings.pl b/src/tests/warnings.pl index c84faae54..b95ac9471 100644 --- a/src/tests/warnings.pl +++ b/src/tests/warnings.pl @@ -3,6 +3,9 @@ t :- x; integer(_). +n :- + \+ \+ \+ foo(_). + x :- a. b, diff --git a/tests/scryer/cli/src_tests/warnings_tests.stderr b/tests/scryer/cli/src_tests/warnings_tests.stderr index f1b4b3bc9..46a3a7c1c 100644 --- a/tests/scryer/cli/src_tests/warnings_tests.stderr +++ b/tests/scryer/cli/src_tests/warnings_tests.stderr @@ -1,2 +1,3 @@ % Warning: integer/1 is a constant source of bugs, use integer_si/1 from library(si) at line 4 of warnings.pl -% Warning: (b,c) attempts to re-define (,)/2 at line 9 of warnings.pl +% Warning: Nested negations can be reduced at line 7 of warnings.pl +% Warning: (b,c) attempts to re-define (,)/2 at line 12 of warnings.pl