mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Visit else in while in any case even if condition is True (PY-28972)
But when condition is `True`, edge to `else` is not created.
This commit is contained in:
@@ -489,11 +489,13 @@ public class PyControlFlowBuilder extends PyRecursiveElementVisitor {
|
||||
myBuilder.addEdge(myBuilder.prevInstruction, instruction);
|
||||
}
|
||||
myBuilder.checkPending(instruction);
|
||||
myBuilder.prevInstruction = head;
|
||||
if (elsePart != null && !isStaticallyTrue) {
|
||||
|
||||
if (elsePart != null) {
|
||||
myBuilder.prevInstruction = !isStaticallyTrue ? head : null;
|
||||
elsePart.accept(this);
|
||||
myBuilder.addPendingEdge(node, myBuilder.prevInstruction);
|
||||
}
|
||||
|
||||
myBuilder.flowAbrupted();
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
while True:
|
||||
pass
|
||||
else:
|
||||
print("ok")
|
||||
@@ -0,0 +1,6 @@
|
||||
0(1) element: null
|
||||
1(2) element: PyWhileStatement
|
||||
2(3) READ ACCESS: True
|
||||
3(1) element: PyStatementList. Condition: True:true
|
||||
4(5) element: PyPrintStatement
|
||||
5() element: null
|
||||
@@ -0,0 +1,7 @@
|
||||
while True:
|
||||
<selection>
|
||||
while True:
|
||||
pass
|
||||
else:
|
||||
break
|
||||
</selection>
|
||||
@@ -274,6 +274,11 @@ public class PyControlFlowBuilderTest extends LightMarkedTestCase {
|
||||
doTest();
|
||||
}
|
||||
|
||||
// PY-28972
|
||||
public void testWhileTrueElse() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
private void doTestFirstStatement() {
|
||||
final String testName = getTestName(false).toLowerCase();
|
||||
configureByFile(testName + ".py");
|
||||
|
||||
@@ -117,6 +117,16 @@ public class PyUnreachableCodeInspectionTest extends PyInspectionTestCase {
|
||||
);
|
||||
}
|
||||
|
||||
// PY-28972
|
||||
public void testWhileTrueElse() {
|
||||
doTestByText(
|
||||
"while True:\n" +
|
||||
" pass\n" +
|
||||
"else:\n" +
|
||||
" <warning descr=\"This code is unreachable\">print(\"ok\")</warning>"
|
||||
);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected Class<? extends PyInspection> getInspectionClass() {
|
||||
|
||||
@@ -270,4 +270,9 @@ public class PyExtractMethodTest extends LightMarkedTestCase {
|
||||
public void testCommentsPrecedingSourceStatement() {
|
||||
doTest("func");
|
||||
}
|
||||
|
||||
// PY-28972
|
||||
public void testInterruptedOuterLoop() {
|
||||
doFail("foo", "Cannot perform refactoring when execution flow is interrupted");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user