PY-909 False positive of "Local variable referenced before assignment" after raise

This commit is contained in:
Oleg Shpynov
2010-04-30 18:59:28 +04:00
parent 1c23e9b8e3
commit d565fdf47c
5 changed files with 35 additions and 2 deletions

View File

@@ -467,7 +467,7 @@ public class PyControlFlowBuilder extends PyRecursiveElementVisitor {
myBuilder.processPending(new ControlFlowBuilder.PendingProcessor() {
public void process(final PsiElement pendingScope, final Instruction instruction) {
final PsiElement pendingElement = instruction.getElement();
if (pendingElement == null){
if (pendingElement == null || !PsiTreeUtil.isAncestor(tryPart, pendingElement, false)){
myBuilder.addPendingEdge(pendingScope, instruction);
return;
}

View File

@@ -0,0 +1,9 @@
try:
from mercurial import lsprof
except ImportError:
raise Error
p = 123
try:
return foo
finally:
print(p)

View File

@@ -0,0 +1,20 @@
0(1) element: null
1(2) element: PyTryExceptStatement
2(3) element: PyTryPart
3(4) element: PyFromImportStatement
4(5) READ ACCESS: mercurial
5(6,10) READ ACCESS: lsprof
6(7) element: PyExceptPart
7(8) READ ACCESS: ImportError
8(9) element: PyRaiseStatement
9(19) READ ACCESS: Error
10(11) element: PyAssignmentStatement
11(12) WRITE ACCESS: p
12(13) element: PyTryExceptStatement
13(14) element: PyTryPart
14(15) element: PyReturnStatement
15(16) READ ACCESS: foo
16(17) element: PyFinallyPart
17(18) element: PyPrintStatement
18(19) READ ACCESS: p
19() element: null

View File

@@ -4,4 +4,4 @@ if markup:
except KeyError:
raise Error
else:
return body
return body

View File

@@ -111,6 +111,10 @@ public class PyControlFlowBuilderTest extends LightMarkedTestCase {
doTest();
}
public void testDoubleTry() throws Exception {
doTest();
}
public void testSelf() throws Exception {
final String testName = getTestName(false).toLowerCase();
configureByFile(testName + ".py");