Java control flow: Handle the case where the variable from the left part of a compound assignment is modified in the right part of the same assignment (IDEA-23725)

This commit is contained in:
Pavel Dolgov
2016-07-25 13:00:38 +03:00
parent 3c8cba0ea0
commit 8c2803eedc
2 changed files with 14 additions and 3 deletions

View File

@@ -1307,9 +1307,6 @@ class ControlFlowAnalyzer extends JavaElementVisitor {
PsiExpression lExpr = PsiUtil.skipParenthesizedExprDown(expression.getLExpression());
if (lExpr instanceof PsiReferenceExpression) {
if (rExpr != null) {
rExpr.accept(this);
}
PsiVariable variable = getUsedVariable((PsiReferenceExpression)lExpr);
if (variable != null) {
if (myAssignmentTargetsAreElements) {
@@ -1324,11 +1321,17 @@ class ControlFlowAnalyzer extends JavaElementVisitor {
if (expression.getOperationTokenType() != JavaTokenType.EQ) {
generateReadInstruction(variable);
}
if (rExpr != null) {
rExpr.accept(this);
}
generateWriteInstruction(variable);
if (myAssignmentTargetsAreElements) finishElement(lExpr);
}
else {
if (rExpr != null) {
rExpr.accept(this);
}
lExpr.accept(this); //?
}
}

View File

@@ -444,4 +444,12 @@ class AssignInAssert {
if(<error descr="Variable 'a' might not have been initialized">a</error>)
System.out.println();
}
}
class CompoundAssign {
void f() {
int i;
<error descr="Variable 'i' might not have been initialized">i</error> += i = 2;
System.out.println(i);
}
}