Fixed false positive in unused locals for condition vars in while loops with if statement at the end (PY-7517)

This commit is contained in:
Andrey Vlasovskikh
2012-09-10 16:58:37 +04:00
parent 5cc3c90c53
commit 9a859a4e65
2 changed files with 13 additions and 3 deletions
@@ -334,10 +334,11 @@ public class PyControlFlowBuilder extends PyRecursiveElementVisitor {
if (list != null) {
myBuilder.startConditionalNode(list, condition, true);
list.accept(this);
final Instruction prevInstruction = myBuilder.prevInstruction != null ? myBuilder.prevInstruction : getPrevInstruction(list);
if (prevInstruction != null) {
myBuilder.addEdge(prevInstruction, instruction); //loop
// Loop edges
if (myBuilder.prevInstruction != null) {
myBuilder.addEdge(myBuilder.prevInstruction, instruction);
}
myBuilder.checkPending(instruction);
}
myBuilder.prevInstruction = head;
if (elsePart != null) {
@@ -294,3 +294,12 @@ def test_unused_variable_in_cycle(x, c):
x -= 1 #pass
if c:
break
# PY-7517
def test_unused_condition_local_with_last_if_in_cycle(c):
x = True
while x:
x = False #pass
if c:
x = True