IDEA-223192 Non-initialized variable error is not displayed in nested switch statement

GitOrigin-RevId: 850afa74fb22dd858bdc8ff7903946678e53d82c
This commit is contained in:
Tagir Valeev
2019-09-24 14:41:00 +07:00
committed by intellij-monorepo-bot
parent 46cf985f64
commit acb3387b1c
2 changed files with 19 additions and 2 deletions

View File

@@ -281,7 +281,7 @@ public class HighlightControlFlowUtil {
PsiElement scope = variable instanceof PsiField
? ((PsiField)variable).getContainingClass()
: variable.getParent() != null ? variable.getParent().getParent() : null;
if (scope instanceof PsiCodeBlock && scope.getParent() instanceof PsiSwitchStatement) {
while (scope instanceof PsiCodeBlock && scope.getParent() instanceof PsiSwitchStatement) {
scope = PsiTreeUtil.getParentOfType(scope, PsiCodeBlock.class);
}

View File

@@ -261,4 +261,21 @@ class ParenthesizedThis {
(this).x = 5; // javac disallows this -- probably a bug in javac
<error descr="Variable 'x' might already have been assigned to">this.x</error> = 6;
}
}
}
class NestedSwitch {
public static void main(String[] args) {
for(int i = 0; i < 8; i++) {
switch (i) {
case 0:
break;
default:
switch (i+1) {
default:
final int var;
<error descr="Variable 'var' might not have been initialized">var</error>++;
}
}
}
}
}