Commit 12410403 authored by Vitja Makarov's avatar Vitja Makarov

CF: Fix try/except, try/finally bug

parent 795c0632
......@@ -1121,6 +1121,7 @@ class ControlFlowAnalysis(CythonTransform):
## XXX: links to exception handling point should be added by
## XXX: children nodes
self.flow.block.add_child(entry_point)
self.flow.nextblock()
self._visit(node.body)
self.flow.exceptions.pop()
......@@ -1181,6 +1182,7 @@ class ControlFlowAnalysis(CythonTransform):
self.flow.block = body_block
## XXX: Is it still required
body_block.add_child(entry_point)
self.flow.nextblock()
self._visit(node.body)
self.flow.exceptions.pop()
if self.flow.loops:
......
......@@ -175,6 +175,7 @@ def test_cdef_attribute():
>>> test_cdef_attribute()
Memoryview is not initialized
local variable 'myview' referenced before assignment
local variable 'myview' referenced before assignment
get_ext_obj called
Memoryview is not initialized
<MemoryView of 'array' object>
......@@ -195,8 +196,11 @@ def test_cdef_attribute():
else:
print "No UnboundLocalError was raised"
# uninitialized assignment is valid
cdef int[:] otherview = myview
cdef int[:] otherview
try:
otherview = myview
except UnboundLocalError, e:
print e.args[0]
try:
print get_ext_obj().mview
......
......@@ -129,3 +129,37 @@ def test_class(cond):
class A:
x = 1
return A.x
def test_try_except_regression(c):
"""
>>> test_try_except_regression(True)
(123,)
>>> test_try_except_regression(False)
Traceback (most recent call last):
...
UnboundLocalError: local variable 'a' referenced before assignment
"""
if c:
a = (123,)
try:
return a
except:
return a
def test_try_finally_regression(c):
"""
>>> test_try_finally_regression(True)
(123,)
>>> test_try_finally_regression(False)
Traceback (most recent call last):
...
UnboundLocalError: local variable 'a' referenced before assignment
"""
if c:
a = (123,)
try:
return a
finally:
return a
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment