diff --git a/python/src/com/jetbrains/python/inspections/PyUnreachableCodeInspection.java b/python/src/com/jetbrains/python/inspections/PyUnreachableCodeInspection.java index d2be547aa163..d58457759b18 100644 --- a/python/src/com/jetbrains/python/inspections/PyUnreachableCodeInspection.java +++ b/python/src/com/jetbrains/python/inspections/PyUnreachableCodeInspection.java @@ -81,7 +81,7 @@ public class PyUnreachableCodeInspection extends LocalInspectionTool { final PsiElement e = instruction.getElement(); if (colors[instruction.num()] != color){ color = colors[instruction.num()]; - if (!warned[color]){ + if (color != 0 && !warned[color]){ warned[color] = true; // Handle ensure parts if (e instanceof PyExceptPart) { diff --git a/python/testData/codeInsight/controlflow/ifelsereturn.py b/python/testData/codeInsight/controlflow/ifelsereturn.py new file mode 100644 index 000000000000..d7f810600c6f --- /dev/null +++ b/python/testData/codeInsight/controlflow/ifelsereturn.py @@ -0,0 +1,7 @@ +if markup: + try: + return renderer + except KeyError: + raise Error +else: + return body \ No newline at end of file diff --git a/python/testData/codeInsight/controlflow/ifelsereturn.txt b/python/testData/codeInsight/controlflow/ifelsereturn.txt new file mode 100644 index 000000000000..5354aedb6509 --- /dev/null +++ b/python/testData/codeInsight/controlflow/ifelsereturn.txt @@ -0,0 +1,11 @@ +0(1) element: null +1(2,8) element: PyIfStatement +2(3) element: PyStatementList. Condition: markup:true +3(4) element: PyTryExceptStatement +4(5) element: PyTryPart +5(10) element: PyReturnStatement +6(7) element: PyExceptPart +7(10) element: PyRaiseStatement +8(9) element: PyElsePart. Condition: markup:false +9(10) element: PyReturnStatement +10() element: null \ No newline at end of file diff --git a/python/testSrc/com/jetbrains/python/PyControlFlowBuilderTest.java b/python/testSrc/com/jetbrains/python/PyControlFlowBuilderTest.java index 9fcce023430c..391d56c820c8 100644 --- a/python/testSrc/com/jetbrains/python/PyControlFlowBuilderTest.java +++ b/python/testSrc/com/jetbrains/python/PyControlFlowBuilderTest.java @@ -78,6 +78,10 @@ public class PyControlFlowBuilderTest extends LightMarkedTestCase { doTest(); } + public void testIfElseReturn() throws Exception { + doTest(); + } + public void testFunction() throws Exception { final String testName = getTestName(false).toLowerCase(); configureByFile(testName + ".py");