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 #13086: fix InnerAssignmentCheck In SwitchRuleAndExpression #14804
base: master
Are you sure you want to change the base?
Conversation
Github, generate report |
cce1a3b
to
83700c0
Compare
413d0be
to
447f762
Compare
Github, generate report |
report is good |
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.
Question
@@ -101,6 +101,7 @@ public class InnerAssignmentCheck | |||
TokenTypes.RESOURCE_SPECIFICATION, | |||
}, | |||
{TokenTypes.EXPR, TokenTypes.LAMBDA}, | |||
{TokenTypes.EXPR, TokenTypes.SWITCH_RULE, TokenTypes.LITERAL_SWITCH, TokenTypes.SLIST}, |
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 we need TokenTypes.SLIST ? And TokenTypes.LITERAL_SWITCH
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.
To make sure that we are in normal Switch context not Switch Expression. if it is {TokenTypes.EXPR, TokenTypes.SWITCH_RULE}
only then we will have no violation if the assignment is in switch expression (one line syntax without braces)
ex
public void test2(int mode) {
int x = 0;
x = switch (mode) {
case 2 -> {
yield x = 2;
}
case 1 -> x = 1; // this will be ok but should be violation
default -> throw new UnsupportedOperationException();
};
}
Switch Expression AST:
|--EXPR -> EXPR [8:10]
| | `--ASSIGN -> = [8:10] <<---
| | |--IDENT -> x [8:8]
| | `--LITERAL_SWITCH -> switch [8:12] <<---
| | |--LPAREN -> ( [8:19]
| | |--EXPR -> EXPR [8:20]
| | | `--IDENT -> mode [8:20]
| | |--RPAREN -> ) [8:24]
| | |--LCURLY -> { [8:26]
| | |--SWITCH_RULE -> SWITCH_RULE [9:12] <<---
| | | |--LITERAL_CASE -> case [9:12]
| | | | `--EXPR -> EXPR [9:17]
| | | | `--NUM_INT -> 1 [9:17]
| | | |--LAMBDA -> -> [9:19]
| | | |--EXPR -> EXPR [9:24] <<---
| | | | `--ASSIGN -> = [9:24]
| | | | |--IDENT -> x [9:22]
| | | | `--NUM_INT -> 1 [9:26]
| | | `--SEMI -> ; [9:27]
| | `--RCURLY -> } [10:8]
switch rule AST
`--SLIST -> { [6:33] <<---
| |--LITERAL_SWITCH -> switch [7:8] <<---
| | |--LPAREN -> ( [7:15]
| | |--EXPR -> EXPR [7:16]
| | | `--IDENT -> mode [7:16]
| | |--RPAREN -> ) [7:20]
| | |--LCURLY -> { [7:22]
| | |--SWITCH_RULE -> SWITCH_RULE [8:12] <<---
| | | |--LITERAL_CASE -> case [8:12]
| | | | `--EXPR -> EXPR [8:17]
| | | | `--NUM_INT -> 1 [8:17]
| | | |--LAMBDA -> -> [8:19]
| | | |--EXPR -> EXPR [8:24] <<---
| | | | `--ASSIGN -> = [8:24]
| | | | |--IDENT -> x [8:22]
| | | | `--NUM_INT -> 1 [8:26]
| | | `--SEMI -> ; [8:27]
| | `--RCURLY -> } [9:8]
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.
@romani ping
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 review documentation to see if we need to update there as well.
Item:
.../checkstyle/checks/coding/innerassignment/InputInnerAssignmentSwitchAndSwitchExpression.java
Outdated
Show resolved
Hide resolved
447f762
to
ab49920
Compare
Github, generate site |
ab49920
to
32b2013
Compare
@mahfouz72 please generate a regression report against openjdk21 |
Github, generate report |
Report generation failed on phase "make_report", |
Github, generate report |
Resolves #13086 :
Diff Regression config: https://gist.githubusercontent.com/mahfouz72/70e0fb4b76668949fd9e0fd3744deddd/raw/0b035184445fee1009e49543af7b1daa6b52f79f/innerass.xml
Diff Regression projects: https://gist.githubusercontent.com/mahfouz72/297d7353d2d0bcec178e1b098109cd9e/raw/546dcdbdff363110fa265ea80d70e36f079c6ee8/projects-to-test-on.properties