diff --git a/python/python-psi-impl/src/com/jetbrains/python/codeInsight/controlflow/PyControlFlowBuilder.java b/python/python-psi-impl/src/com/jetbrains/python/codeInsight/controlflow/PyControlFlowBuilder.java index 997f863adfc4..4bdde537b62c 100644 --- a/python/python-psi-impl/src/com/jetbrains/python/codeInsight/controlflow/PyControlFlowBuilder.java +++ b/python/python-psi-impl/src/com/jetbrains/python/codeInsight/controlflow/PyControlFlowBuilder.java @@ -500,7 +500,7 @@ public class PyControlFlowBuilder extends PyRecursiveElementVisitor { } exitInstructions.add(myBuilder.prevInstruction); - myBuilder.prevInstruction = addTransparentInstruction(); + myBuilder.prevInstruction = addTransparentInstruction(node); for (Instruction exitInstruction : Lists.reverse(exitInstructions)) { myBuilder.addEdge(exitInstruction, myBuilder.prevInstruction); diff --git a/python/testData/codeInsight/controlflow/WithRaiseException.txt b/python/testData/codeInsight/controlflow/WithRaiseException.txt index 9082637671d5..9fa608e1bcf6 100644 --- a/python/testData/codeInsight/controlflow/WithRaiseException.txt +++ b/python/testData/codeInsight/controlflow/WithRaiseException.txt @@ -4,7 +4,7 @@ 3(16) exit context manager: context_manager 4(5,3) element: PyIfStatement 5(6,7,3) READ ACCESS: c -6(13) element: null. Condition: c:false +6(13,3) element: null. Condition: c:false 7(8) element: null. Condition: c:true 8(3,9) ASSERTTYPE ACCESS: c 9(10) element: PyStatementList diff --git a/python/testSrc/com/jetbrains/python/inspections/PyUnreachableCodeInspectionTest.java b/python/testSrc/com/jetbrains/python/inspections/PyUnreachableCodeInspectionTest.java index 23a349e58b45..96daf7ca47dc 100644 --- a/python/testSrc/com/jetbrains/python/inspections/PyUnreachableCodeInspectionTest.java +++ b/python/testSrc/com/jetbrains/python/inspections/PyUnreachableCodeInspectionTest.java @@ -24,6 +24,21 @@ public class PyUnreachableCodeInspectionTest extends PyInspectionTestCase { public void testUnreachable() { runWithLanguageLevel(LanguageLevel.PYTHON26, () -> doTest()); } + + // PY-82712 + public void testIfInsideTryExcept() { + doTestByText(""" +try: + if a==1: + print(0) + else: + print(1) +finally: + print(2) +print("Reachable") + """); + } + // PY-81482 public void testTryAssertFinally() {