mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Consider elif inner instructions as branching points (PY-23003)
This commit is contained in:
@@ -360,9 +360,9 @@ public class PyControlFlowBuilder extends PyRecursiveElementVisitor {
|
||||
assertionEvaluator = new PyTypeAssertionEvaluator();
|
||||
if (condition != null) {
|
||||
lastCondition = condition;
|
||||
lastBranchingPoints = getPrevInstructions(lastCondition);
|
||||
condition.accept(this);
|
||||
condition.accept(assertionEvaluator);
|
||||
lastBranchingPoints = getPrevInstructions(lastCondition);
|
||||
}
|
||||
// Set the head as the last instruction of condition
|
||||
getPrevInstructions(lastCondition).forEach(pair -> myBuilder.addPendingEdge(pair.getFirst(), pair.getSecond()));
|
||||
|
||||
@@ -7,9 +7,9 @@
|
||||
6(7) element: PyStatementList. Condition: a == b:true
|
||||
7(8) element: PyAssignmentStatement
|
||||
8(25) WRITE ACCESS: var
|
||||
9(10,22) element: PyIfPartElif. Condition: a == b:false
|
||||
9(10) element: PyIfPartElif. Condition: a == b:false
|
||||
10(11) READ ACCESS: aa
|
||||
11(12) READ ACCESS: bb
|
||||
11(12,22) READ ACCESS: bb
|
||||
12(13) element: PyIfPartElif. Condition: aa == bb:true
|
||||
13(14) element: PyAssignmentStatement
|
||||
14(15) READ ACCESS: same_changet_expression
|
||||
|
||||
@@ -20,17 +20,17 @@
|
||||
19(20,22,37) READ ACCESS: x
|
||||
20(21) element: PyStatementList. Condition: x == 0:true
|
||||
21(37,40) element: PyBreakStatement
|
||||
22(23,26,37) element: PyIfPartElif. Condition: x == 0:false
|
||||
23(24,37) READ ACCESS: x
|
||||
22(23,37) element: PyIfPartElif. Condition: x == 0:false
|
||||
23(24,26,37) READ ACCESS: x
|
||||
24(25,37) element: PyIfPartElif. Condition: x == 1:true
|
||||
25(7,37) element: PyContinueStatement
|
||||
26(27,31,37) element: PyIfPartElif. Condition: x == 1:false
|
||||
27(28,37) READ ACCESS: x
|
||||
26(27,37) element: PyIfPartElif. Condition: x == 1:false
|
||||
27(28,31,37) READ ACCESS: x
|
||||
28(29,37) element: PyIfPartElif. Condition: x == 2:true
|
||||
29(30,37) element: PyRaiseStatement
|
||||
30(37) READ ACCESS: Exception
|
||||
31(32,35,37) element: PyIfPartElif. Condition: x == 2:false
|
||||
32(33,37) READ ACCESS: x
|
||||
31(32,37) element: PyIfPartElif. Condition: x == 2:false
|
||||
32(33,35,37) READ ACCESS: x
|
||||
33(34,37) element: PyIfPartElif. Condition: x == 3:true
|
||||
34(37) element: PyReturnStatement
|
||||
35(36,37) element: PyAssignmentStatement
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.jetbrains.python.fixtures;
|
||||
|
||||
import com.intellij.codeInspection.ex.InspectionProfileImpl;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.jetbrains.python.PythonFileType;
|
||||
import com.jetbrains.python.inspections.PyInspection;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -43,6 +44,12 @@ public abstract class PyInspectionTestCase extends PyTestCase {
|
||||
assertSdkRootsNotParsed(currentFile);
|
||||
}
|
||||
|
||||
protected void doTestByText(@NotNull String text) {
|
||||
final PsiFile currentFile = myFixture.configureByText(PythonFileType.INSTANCE, text);
|
||||
configureInspection();
|
||||
assertSdkRootsNotParsed(currentFile);
|
||||
}
|
||||
|
||||
protected void doMultiFileTest() {
|
||||
doMultiFileTest("a.py");
|
||||
}
|
||||
|
||||
@@ -169,6 +169,20 @@ public class PyRedeclarationInspectionTest extends PyInspectionTestCase {
|
||||
doTest();
|
||||
}
|
||||
|
||||
// PY-23003
|
||||
public void testVariableUsedInElIf() {
|
||||
doTestByText(
|
||||
"for file in ['test_file']:\n" +
|
||||
" block = False\n" +
|
||||
" if a:\n" +
|
||||
" block = True\n" +
|
||||
" elif block and b:\n" +
|
||||
" block = False\n" +
|
||||
" else:\n" +
|
||||
" print(c)"
|
||||
);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected Class<? extends PyInspection> getInspectionClass() {
|
||||
|
||||
Reference in New Issue
Block a user