Commit a86c19f1 authored by Stefan Behnel's avatar Stefan Behnel

warn about unreachable except-else clause

--HG--
extra : amend_source : 4c6b14a416f49c6942dc5fafc87b1ea2120bac7b
parent 08077345
......@@ -2164,7 +2164,9 @@ class RemoveUnreachableCode(CythonTransform):
def visit_TryExceptStatNode(self, node):
self.visitchildren(node)
if node.body.is_terminator:
if node.body.is_terminator and node.else_clause:
if self.current_directives['warn.unreachable']:
warning(node.else_clause.pos, "Unreachable code", 2)
node.else_clause = None
return node
......
......@@ -23,9 +23,19 @@ def conditional(a, b):
return 3
print 'oops'
def try_except():
try:
raise TypeError
except ValueError:
pass
else:
print 'unreachable'
_ERRORS = """
6:4: Unreachable code
11:8: Unreachable code
15:8: Unreachable code
24:4: Unreachable code
32:8: Unreachable code
"""
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