Commit 575eb02f authored by Stefan Behnel's avatar Stefan Behnel

Make "break" outside of loops a syntax error also inside of try-except blocks.

Closes #1726.
parent 7998f0af
...@@ -5508,6 +5508,7 @@ class IndirectionNode(StatListNode): ...@@ -5508,6 +5508,7 @@ class IndirectionNode(StatListNode):
def __init__(self, stats): def __init__(self, stats):
super(IndirectionNode, self).__init__(stats[0].pos, stats=stats) super(IndirectionNode, self).__init__(stats[0].pos, stats=stats)
class BreakStatNode(StatNode): class BreakStatNode(StatNode):
child_attrs = [] child_attrs = []
...@@ -6684,8 +6685,8 @@ class TryExceptStatNode(StatNode): ...@@ -6684,8 +6685,8 @@ class TryExceptStatNode(StatNode):
except_error_label = code.new_label('except_error') except_error_label = code.new_label('except_error')
except_return_label = code.new_label('except_return') except_return_label = code.new_label('except_return')
try_return_label = code.new_label('try_return') try_return_label = code.new_label('try_return')
try_break_label = code.new_label('try_break') try_break_label = code.new_label('try_break') if old_break_label else None
try_continue_label = code.new_label('try_continue') try_continue_label = code.new_label('try_continue') if old_continue_label else None
try_end_label = code.new_label('try_end') try_end_label = code.new_label('try_end')
exc_save_vars = [code.funcstate.allocate_temp(py_object_type, False) exc_save_vars = [code.funcstate.allocate_temp(py_object_type, False)
......
...@@ -27,12 +27,33 @@ def bool_result(): ...@@ -27,12 +27,33 @@ def bool_result():
return True return True
def break_after_loop():
for _ in range(2):
pass
if bool_result():
break
try:
if bool_result():
break
except Exception:
pass
if bool_result():
break
_ERRORS = u''' _ERRORS = u'''
4:0: break statement not inside loop 4:0: break statement not inside loop
7:4: break statement not inside loop 7:4: break statement not inside loop
10:4: break statement not inside loop 10:4: break statement not inside loop
13:4: break statement not inside loop 13:4: break statement not inside loop
15:5: break statement not inside loop
18:5: break statement not inside loop 18:5: break statement not inside loop
22:4: break statement not inside loop 22:4: break statement not inside loop
24:4: break statement not inside loop 24:4: break statement not inside loop
35:8: break statement not inside loop
39:12: break statement not inside loop
44:8: break statement not inside loop
''' '''
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