Skip to content
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

Issue #14506: False positive for UnusedLocalVariable #14672

Merged
merged 1 commit into from
May 18, 2024

Conversation

Kevin222004
Copy link
Contributor

@Kevin222004 Kevin222004 commented Mar 17, 2024

@Kevin222004
Copy link
Contributor Author

Github, generate report

Copy link
Contributor

@rdiachenko rdiachenko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

Copy link
Member

@nrmancuso nrmancuso left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor item:

@nrmancuso
Copy link
Member

Good to merge, @Kevin222004 please make CI happy

Copy link
Member

@romani romani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Items

Copy link
Member

@romani romani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok to merge

@romani romani assigned rnveach and unassigned romani Apr 7, 2024
TokenTypes.ELIST,
TokenTypes.INDEX_OP,
TokenTypes.ASSIGN,
TokenTypes.LITERAL_SWITCH,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure why LITERAL_SWITCH and why not something that makes more sense like EXPR? A switch is not technically anything used with increments/decrements. At least the other 3 make somewhat more sense.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whenever the token is of type TokenTypes.ELIST, TokenTypes.INDEX_OP, TokenTypes.ASSIGN, in that cases the Variable is been used for example

int h = ++m;

the last will be

|       |       |--VARIABLE_DEF -> VARIABLE_DEF [66:8]
|       |       |   |--MODIFIERS -> MODIFIERS [66:8]
|       |       |   |--TYPE -> TYPE [66:8]
|       |       |   |   `--LITERAL_INT -> int [66:8]
|       |       |   |--IDENT -> h [66:12]
|       |       |   `--ASSIGN -> = [66:14]
|       |       |       `--EXPR -> EXPR [66:16]
|       |       |           `--INC -> ++ [66:16]
|       |       |               `--IDENT -> m [66:18]

this is the one case where expr parent is TokenTypes.ASSIGN

know particular in switch

        switch (i++) {

the ast will be

        |       |--LITERAL_SWITCH -> switch [12:8]
        |       |   |--LPAREN -> ( [12:15]
        |       |   |--EXPR -> EXPR [12:17]
        |       |   |   `--POST_INC -> ++ [12:17]
        |       |   |       `--IDENT -> i [12:16]
        |       |   |--RPAREN -> ) [12:19]

the way to declare the i++ as used I have to put their TokenTypes.LiteralSwitch

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and why not something that makes more sense like EXPR?

I am not seeing this specifically answered.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Specifically in this function we are trying to find out whether the increment or decrement variable is used or not and in case of TokenTypes.ELIST, TokenTypes.INDEX_OP, TokenTypes.ASSIGN if this tokens are the parent of expr then it is used and they are understandable for example again TokenTypes.ASSIGN

int h = ++m;

this case of LiteralSwitch is slightly unique in general as per the check logic if the increment decrement variable is alone then the variable seems to be unused but in this case, it is not true that's why the TokenTypes.LiteralSwitch is used in the sense if it is parent then the variable is used as I have explained in above comment.
and I also don't see any way some how only EXPR can be used and we can declare this as used variable.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not fully understanding and this isn't making sense.

Either way, the javadoc needs to be updated for this method for the new token being examined.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

@Kevin222004 Kevin222004 Apr 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rnveach sorry for the delay. I will update the pr as soon as possible.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Kevin222004, ping, please find time to fix this PR. We are almost done. Passing of last reviewer is left only.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am sorry for such long delay will fix with in 2 days

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@rnveach rnveach merged commit 6bb41a4 into checkstyle:master May 18, 2024
114 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants