Call pushExpressionResult after field flushing so CommonDataflow (and other clients) has flushed result

Fixes IDEA-230116 Incorrect "Redundant operation on empty container" inspection result

GitOrigin-RevId: d764150c114bca699202dc39160efc084c077036
This commit is contained in:
Tagir Valeev
2020-01-17 15:05:44 +07:00
committed by intellij-monorepo-bot
parent 9e5e9dadef
commit acd079d592
3 changed files with 35 additions and 3 deletions

View File

@@ -233,7 +233,11 @@ public class StandardInstructionVisitor extends InstructionVisitor {
DfaValue defaultResult = runner.getFactory().getObjectType(returnType, DfaPsiUtil.getElementNullability(returnType, method));
Set<DfaCallState> currentStates = Collections.singleton(new DfaCallState(state.createClosureState(), callArguments));
for (MethodContract contract : contracts) {
currentStates = addContractResults(contract, currentStates, runner.getFactory(), new HashSet<>(), defaultResult, methodRef);
Set<DfaMemoryState> results = new HashSet<>();
currentStates = addContractResults(contract, currentStates, runner.getFactory(), results, defaultResult, methodRef);
for (DfaMemoryState result : results) {
pushExpressionResult(result.pop(), new ResultOfInstruction(methodRef), result);
}
}
for (DfaCallState currentState: currentStates) {
pushExpressionResult(defaultResult, new ResultOfInstruction(methodRef), currentState.myMemoryState);
@@ -366,7 +370,7 @@ public class StandardInstructionVisitor extends InstructionVisitor {
}
}
for (DfaCallState callState : currentStates) {
pushExpressionResult(defaultResult, instruction, callState.myMemoryState);
callState.myMemoryState.push(defaultResult);
finalStates.add(callState.myMemoryState);
}
@@ -376,6 +380,7 @@ public class StandardInstructionVisitor extends InstructionVisitor {
if (instruction.shouldFlushFields()) {
state.flushFields();
}
pushExpressionResult(state.pop(), instruction, state);
result[i++] = new DfaInstructionState(runner.getInstruction(instruction.getIndex() + 1), state);
}
return result;
@@ -507,7 +512,7 @@ public class StandardInstructionVisitor extends InstructionVisitor {
}
if(state != null) {
DfaValue result = contract.getReturnValue().getDfaValue(factory, defaultResult, new DfaCallState(state, arguments));
pushExpressionResult(result, new ResultOfInstruction(expression), state);
state.push(result);
finalStates.add(state);
}
}