-
Notifications
You must be signed in to change notification settings - Fork 150
Warnings collection #2602
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
hurufu
wants to merge
11
commits into
mthom:master
Choose a base branch
from
hurufu:warnings_collection
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Warnings collection #2602
Changes from 5 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
4c26ec6
Warn on redefinition of builtin predicates
hurufu 659f993
Add unit tests
hurufu b66bb8e
Use phrase for warning formatting
hurufu c11d5fe
Reorganize code + remove useless output_stream
hurufu be3e011
Suggest using library(si)
hurufu 2d1ebf0
Warn about deeply nested negation
hurufu df99b4e
Fix warning text after review
hurufu 43691eb
Reorganize code
hurufu af3c654
Extend builtins check to \+
hurufu 8eb906a
Detect undeclared meta-predicates
hurufu c6d5921
Warn about invalid arithmetic relations
hurufu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
:- module(warnings, []). | ||
|
||
:- use_module(library(format)). | ||
:- use_module(library(pio)). | ||
|
||
warn_fail(Format, Vars) :- | ||
warn_fail(user_error, Format, Vars). | ||
warn_fail(Stream, Format, Vars) :- | ||
prolog_load_context(file, File), | ||
prolog_load_context(term_position, position_and_lines_read(_,Line)), | ||
phrase_to_stream( | ||
( | ||
"% Warning: ", format_(Format,Vars), format_(" at line ~d of ~a~n",[Line,File]) | ||
), | ||
Stream | ||
), | ||
false. | ||
|
||
% FIXME: Replace with predicate_property(_, built_in) when #2600 will be ready | ||
builtin((_;_)). | ||
builtin((_,_)). | ||
builtin((_->_)). | ||
|
||
unsound_type_test(atom(_)). | ||
unsound_type_test(atomic(_)). | ||
unsound_type_test(integer(_)). | ||
|
||
% Warn about builtin predicates re-definition. It can happen by mistake for | ||
% example: | ||
% x :- a. b, c. | ||
% | ||
user:term_expansion(G, _) :- | ||
nonvar(G), | ||
builtin(G), | ||
functor(G, F, 2), | ||
warn_fail("(~q) attempts to re-define ~w", [G, F/2]). | ||
|
||
% Warn about unsound type test predicates and suggest using library(si). | ||
% Observe that following queries yield different results: | ||
% | ||
% ?- X=1, integer(X). | ||
% true. | ||
% ?- integer(X), X=1. | ||
% false. | ||
% | ||
user:goal_expansion(G, _) :- | ||
nonvar(G), | ||
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]). | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
:- use_module(library(warnings)). | ||
|
||
t :- | ||
x; integer(_). | ||
|
||
x :- | ||
a. | ||
b, | ||
c. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
% 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
error(permission_error(modify,static_procedure,(',')/2),load/1). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
args = [ | ||
"-f", | ||
"--no-add-history", | ||
"src/tests/warnings.pl", | ||
"-g", "halt"] |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.