-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
LITERAL_WHEN and LAND tokens in switch statements should have EXPR child #15082
Comments
@nrmancuso Are you able to look at other checkstyle/src/main/resources/com/puppycrawl/tools/checkstyle/grammar/java/JavaLanguageParser.g4 Line 503 in 11dcd18
explicitConstructorInvocation
checkstyle/src/main/resources/com/puppycrawl/tools/checkstyle/grammar/java/JavaLanguageParser.g4 Line 625 in 11dcd18
fieldAccessNoIdent
checkstyle/src/main/resources/com/puppycrawl/tools/checkstyle/grammar/java/JavaLanguageParser.g4 Line 750 in 11dcd18
primary
checkstyle/src/main/resources/com/puppycrawl/tools/checkstyle/grammar/java/JavaLanguageParser.g4 Lines 770 to 776 in 11dcd18
String templates will be removed in #14805 , so this can also be ignored. I will see if I can create some code to make this easier. |
Code examples from #15082 (comment) :
Tree:
JLS: |
These were all existing oddities (pre ANTLR4), which was one of the reasons why I had the two different rules in the first place. We could certainly open tickets for each one of these to discuss if we should change our grammar, but these will be massively breaking at this point. |
I agree, I will open the tickets to discuss. |
I did not create an issue for this. This is a sub-set of the You can see in our grammar only checkstyle/src/main/resources/com/puppycrawl/tools/checkstyle/grammar/java/JavaLanguageParser.g4 Lines 689 to 690 in 11dcd18
You can see in the tree,
JLS: |
@nrmancuso , please update issue title to reference that we will add expressions to |
Not sure what you mean by this, the issue description accurately describes exactly what is changing here. We aren't adding imaginary EXPR nodes directly under the LITERAL_CASE token. |
I was about title, as the only part that is visible in release notes. |
Sorry, typo on my part, title describes what is changing here, we aren't adding an imaginary EXPR node to LITERAL_CASE. |
LITERAL_WHEN
token should have EXPR
childCASE_GROUP
and LITERAL_WHEN
token should have EXPR
child
CASE_GROUP
and LITERAL_WHEN
token should have EXPR
child
@romani There is no case group token here.
|
There is no But all switches got new EXPR token. We detected issue on @nrmancuso , @rnveach , please consider renaming title. |
This is false, because...
checkstyle/src/main/resources/com/puppycrawl/tools/checkstyle/grammar/java/JavaLanguageParser.g4 Line 925 in 9d33dde
Guard appears only on when and && (we may update to guardedPattern ). We shouldn't be updating switches with normal/old cases. I feel this is the issue with saying "case" without any additional context.
@nrmancuso can probably understand the grammar better if we can say "pattern guards" but it seems like the issue should be titled |
I look at it not from grammar perspective, but from resulted AST. Our API is AST, not a grammar, even they are related. |
Even still, expr is not added to case. It is added to |
I've updated the title to be as correct and google-able as possible, anyone that has an issue with it can change the title again themselves. Users can come to this issue, see the painful discussion here, and understand all details about this change and the associated PR if they need to. The following statements are not accurate:
|
Originally posted by @rnveach in #15044 (comment)
Expressions used in
case
ofswitch
are not caught by BooleanExpressionComplexity.This is the issue. We only check the count when we finish an expression. However, this
when
isn't an expression.the same problem is for
case
with&&
or any other expression like operator:According to the JLS (unless I am looking at the wrong area), this guard says it is an expression. Is this a bug in our grammar that we are missing an expression token?
https://docs.oracle.com/javase/specs/jls/se22/html/jls-14.html#jls-14.11.1
Edit: It does look like our grammar does say expression.
checkstyle/src/main/resources/com/puppycrawl/tools/checkstyle/grammar/java/JavaLanguageParser.g4
Lines 913 to 914 in 11dcd18
Edit 2: It looks like it is an issue using
expr
overexpression
in the grammar.checkstyle/src/main/resources/com/puppycrawl/tools/checkstyle/grammar/java/JavaLanguageParser.g4
Lines 683 to 687 in 11dcd18
examples of EXPR in our tree:
https://checkstyle.sourceforge.io/apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#SLIST
https://checkstyle.sourceforge.io/apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#EXPR
location of EXPR is odd when comparing to ASSIGN:
vs
The text was updated successfully, but these errors were encountered: