From 7ceae97d25c3bda7d17c9bd36ad864a8a23ac066 Mon Sep 17 00:00:00 2001 From: Oleg Shpynov Date: Wed, 3 Feb 2010 19:05:26 +0300 Subject: [PATCH] =?UTF-8?q?PY-459=20Unreachable=20code=20positively=20fail?= =?UTF-8?q?s=20-=20if=20(=E2=80=8Btry=E2=80=8B..=20except=E2=80=8B.?= =?UTF-8?q?=E2=80=8B.)=20else=20return?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../inspections/PyUnreachableCodeInspection.java | 2 +- .../testData/codeInsight/controlflow/ifelsereturn.py | 7 +++++++ .../testData/codeInsight/controlflow/ifelsereturn.txt | 11 +++++++++++ .../jetbrains/python/PyControlFlowBuilderTest.java | 4 ++++ 4 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 python/testData/codeInsight/controlflow/ifelsereturn.py create mode 100644 python/testData/codeInsight/controlflow/ifelsereturn.txt 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");