Issue #13328: Kill mutation for UnusedLocalVariableCheck 8#13151
Issue #13328: Kill mutation for UnusedLocalVariableCheck 8#13151romani merged 1 commit intocheckstyle:masterfrom
Conversation
|
Github, generate report |
|
Github, generate report |
There was a problem hiding this comment.
https://checkstyle.org/apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LITERAL_NEW
Strange that we used last child, not clear why
Items
src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/UnusedLocalVariableCheck.java
Show resolved
Hide resolved
romani
left a comment
There was a problem hiding this comment.
Ok to merge if reports are clean
|
Please ignore survivng mutation it will be covering at #13331 |
| final DetailAST updatedScope = literalNewAst.getLastChild(); | ||
| final Deque<VariableDesc> instAndClassVarDeque = new ArrayDeque<>(); | ||
| instanceAndClassVarStack.forEach(instVar -> { | ||
| final VariableDesc variableDesc = new VariableDesc(instVar.getName(), | ||
| instVar.getTypeAst(), updatedScope); | ||
| instVar.getTypeAst(), literalNewAst); |
There was a problem hiding this comment.
I am not ok with pitest complaining here. The logic is correct but it breaks the integrity of the check. We use last-child because we have a set definition of scope.
The check by design uses { or for for determining scope. Extending this to literalNew is error-prone as it serves no value. The check is designed to have only the above-mentioned token as scope and this change can make extending this check difficult because one more case has to be handled.
I vote for suppressing this pitest mutation.
@romani @rdiachenko Please share your thoughts.
There was a problem hiding this comment.
If this value does not matter in current context, let's put null there or use some ctor without this value.
There was a problem hiding this comment.
The value of scope matters, it is used to pop out the variables at the right time (from the proper scope). I am saying this should stay:
final DetailAST updatedScope = literalNewAst.getLastChild();And pitest should be suppressed in this case. This is an intentional check design otherwise every other parent-level token can be considered as scope but we have limited it due to intentional design and ease of maintenance.
There was a problem hiding this comment.
I do not see this.
there are only 2 usages of this class with scope defined in constructor: modified case and case
but this method also use parent, not a last child:
There was a problem hiding this comment.
but you might mean that we do validation based on scope token type
so any not SCOPES will be skiped here
There was a problem hiding this comment.
Once again after evaluating and following pitest of pr #13152 pitest) it looks to me that the design needs to be changed or the logic looks very clean to me so let it be suppressed
There was a problem hiding this comment.
I lost track of this PR, sorry for no response for long, I will do deep dive one more time to make decision.
There was a problem hiding this comment.
Why complicate the check more by adding a new scope when the current definition of scope makes everything work.
We are not extending SCOPES with a new scope.
So it does not matter if we do checking at OBJBLOCK or LITERAL_NEW, the result would be the same.
I didn't get it, why the result would be the same? If it's the same and we are not extending SCOPES and there is no input test, why shouldn't we accept Kevin's change?
There was a problem hiding this comment.
We are not extending SCOPES with a new scope.
We are not adding anything to SCOPES static field but now a variable has LITERAL_NEW as scope which is not what the check promises. Sort of violates the contract.
I didn't get it, why the result would be the same? If it's the same and we are not extending SCOPES and there is no input test, why shouldn't we accept Kevin's change?
The result would be the same because no instead of both OBJBLOCK and LITERAL_NEW don't contribute anything to the violations (as they are non-local). On top of that, it won't affect the stack order because they are popped off at the right time. (With this change, at LITERAL_NEW instead of OBJBLOCK)
There was a problem hiding this comment.
I tried to play with code preserving OBJBLOCK and resolving the mutation - https://github.com/checkstyle/checkstyle/pull/13546/files.
@Vyom-Yadav what do you think about such a change, assuming it passes all needed ci checks?
|
@Kevin222004 , please rebase to resolve conflict. |
|
@Kevin222004 , conflict again |
|
#13151 (comment) Resolved |
rdiachenko
left a comment
There was a problem hiding this comment.
lgtm
I tried a different approach here #13546 (comment) but it is less safe and may break existing logic. I'd rather go with the current approach with is simpler and safer.
|
@Kevin222004 please resolve conflicts |
romani
left a comment
There was a problem hiding this comment.
I am ok to merge.
Absence of any mutation will not next contributor to extend list of situations.
Vyom-Yadav
left a comment
There was a problem hiding this comment.
Though this is not what I wanted, but I can see why this is the better solution.
While designing this check, I didn't keep local classes in mind ('cause colliding variable names in local classes is really rare, and then their nesting, it can get reallyyy complex).
Pitest is indirectly indicating that only, this breaks the contract of the check but the logic is working fine. I will come back to this check sometime with hopefully a better design.
LGTM!
|
By merging this we close a door to all other leaks for survival, one day we will see how to make design better, we already spent too much time on this, we need a break. |
Issue #13328: Kill mutation for UnusedLocalVariableCheck 8
Check :-
https://checkstyle.org/checks/coding/unusedlocalvariable.html#UnusedLocalVariable
Mutation
checkstyle/config/pitest-suppressions/pitest-coding-2-suppressions.xml
Lines 75 to 82 in 554a87e
Explaination
the updated scope is changes as only literalNewAst Actually it is not affecting any thing if we make it as literalNewast or objBlock as its last child
Regression :-
Diff Regression config: https://gist.githubusercontent.com/Kevin222004/0dbdfb487f8e9a050ed0e6356f1a35b4/raw/31f7927f400e11e4285e86fd086b373095227848/unusedLocal.xml
Diff Regression projects: https://gist.githubusercontent.com/Kevin222004/21e3934e85f802e2fbd48af06d122364/raw/604256badd733d8568064f371d55657c04b00dfd/test-projects-2.properties
Report label: Final-Regression-1