Files
openide/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlightingPatternsInSwitch/MultipleReferencesToPatternVariable.java
Nikita Eshkeev 5657d92469 [java][switch resolve] IDEA-273929 Good code red - cannot resolve symbol in switch statement group
IDEA used to allow resolving if a statement or an expression that uses a pattern variable in a switch case label follows the switch case label immediately. This led to errors in resolving references to pattern variables when their enclosing statement or expression is not the immediate right sibling of the case label.

Now IDEA looks for a switch case label among all the left siblings of the currently analyzing scope and enables resolving if a case label is found, and it's the same switch case label that is being analyzed.

GitOrigin-RevId: 758c34fde30db2fe9692d8076c49af2b3efae38f
2021-07-28 19:15:34 +00:00

19 lines
384 B
Java

class Main {
void multipleReferencesToPatternVariable(Object o) {
switch (o) {
case Character c:
if (c == 7) {
System.out.println(c > 2);
}
if (c == 9) {
System.out.println(c + 2);
}
// hello, world
if (c == 11) { }
System.out.println(c);
default:
System.out.println();
}
}
}