ControlFlowUtil#isVariableAssignedInLoop: evaluate constant conditions

Fixes IDEA-186306 good code red: variable might be assigned in loop
This commit is contained in:
Tagir Valeev
2018-02-08 13:29:49 +07:00
parent 4234f0d140
commit c8f3d1e20c
2 changed files with 20 additions and 1 deletions
@@ -111,4 +111,23 @@ class T3a {
<error descr="Variable 'b' might already have been assigned to">b</error> = true; // red
System.out.println(b);
}
}
class T29 {
// IDEA-186306
private final int j;
T29 (int b) {
do {
j = 34; // guaranteed to only be executed once
if (true) break;
} while (b == 1);
}
}
class T29a {
private final int j;
T29a (int b) {
do {
<error descr="Variable 'j' might be assigned in loop">j</error> = 34; // not guaranteed by JLS to only be executed once
if (j > 0) break;
} while (b == 1);
}
}