-
Notifications
You must be signed in to change notification settings - Fork 19
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
Adding notcheckdeadcode option #633
base: master
Are you sure you want to change the base?
Adding notcheckdeadcode option #633
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for starting work on this issue!
At the moment this isn't tested at all, so please do add a new test directory that enables the option.
When I tried it before, there was a problem with the Nullness Checker, so do use that.
Write tests e.g. like the one in the issue and things like an empty try block where an impossible catch block does something bad.
@@ -150,6 +150,9 @@ | |||
// org.checkerframework.framework.source.SourceChecker.report | |||
"warns", | |||
|
|||
// Make checker ignore the expression in dead branch | |||
"notCheckDeadCode", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about ignoreDeadCode
to have more symmetry with other ignoreXXX
options?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By convention, for each option we list the main point where that option is used. Please add such a reference.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By convention, for each option we list the main point where that option is used. Please add such a reference.
Thanks, already addressed the comment in 1d1c348
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about
ignoreDeadCode
to have more symmetry with otherignoreXXX
options?
addressed this comment in 58f4773
} | ||
}); | ||
*/ | ||
if (checker.hasOption("notCheckDeadCode")) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here, and probably in the BaseTypeVisitor
, put the option into a protected variable, so that we don't look up the option multiple times. See how other options are handled.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here, and probably in the
BaseTypeVisitor
, put the option into a protected variable, so that we don't look up the option multiple times. See how other options are handled.
addressed this comment in 2540cd3
Thanks, I will add test cases later. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Ao-senXiong Were there more tests you wanted to add? Can you wrap up this PR?
@@ -150,6 +150,10 @@ | |||
// org.checkerframework.framework.source.SourceChecker.report | |||
"warns", | |||
|
|||
// Make checker ignore the expression in dead branch | |||
// org.checkerframework.framework.common.basetype.BaseTypeVisitor.shouldSkipUses | |||
"ignoreCheckDeadCode", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As noted in #633 (comment) ignoreDeadCode
would seem simpler.
@@ -0,0 +1,31 @@ | |||
// @skip-test until the bug is fixed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do these tests not work?
// :: error: (dereference.of.nullable) | ||
obj.toString(); | ||
for (int i = 0; i < 0; i++) { | ||
obj.toString(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a comment to each dead branch why they are dead.
@@ -3,6 +3,9 @@ Version 3.40.0-eisop3 (November ??, 2023) | |||
|
|||
**User-visible changes:** | |||
|
|||
Add a new command-line argument `-AignoreCheckDeadCode` disables the checker for code in dead expression. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When you update the branch, make sure to move this to the next upcoming release.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And try to make this sentence easier to read.
// return true; | ||
// } | ||
if (ignoreCheckDeadCode) { | ||
System.out.printf("shouldSkipUses: %s: %s%n", exprTree.getClass(), exprTree); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is debugging output and should remain a comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, the debugging output shouldn't be guarded by the new condition.
You can combine the two 'if's into one check.
// if (atypeFactory.isUnreachable(tree)) { | ||
// return super.visitMemberSelect(tree, p); | ||
// } | ||
if (ignoreCheckDeadCode) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why make these two separate 'if's?
|
||
@Parameterized.Parameters | ||
public static String[] getTestDirs() { | ||
return new String[] {"nullness-deadbranch"}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about nullness-ignoredeadcode
to name the directory after the option?
@@ -3,6 +3,9 @@ Version 3.40.0-eisop3 (November ??, 2023) | |||
|
|||
**User-visible changes:** | |||
|
|||
Add a new command-line argument `-AignoreCheckDeadCode` disables the checker for code in dead expression. | |||
This option is not enabled by default. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please also add documentation in the manual, where we have a short paragraph for each option.
Fixes #627
Do you need more test cases on this option?