Forbid arguments to break
and continue
This commit is contained in:
parent
d03b1be686
commit
7ed31a18f3
2
NEWS
2
NEWS
@ -34,6 +34,8 @@ Changes from 0.13.0
|
|||||||
* Fixed a crash when `with` suppresses an exception. `with` now returns
|
* Fixed a crash when `with` suppresses an exception. `with` now returns
|
||||||
`None` in this case.
|
`None` in this case.
|
||||||
* `assoc` now evaluates its arguments only once each
|
* `assoc` now evaluates its arguments only once each
|
||||||
|
* `break` and `continue` now raise an error when given arguments
|
||||||
|
instead of silently ignoring them
|
||||||
|
|
||||||
[ Misc. Improvements ]
|
[ Misc. Improvements ]
|
||||||
* `read`, `read_str`, and `eval` are exposed and documented as top-level
|
* `read`, `read_str`, and `eval` are exposed and documented as top-level
|
||||||
|
@ -1123,6 +1123,7 @@ class HyASTCompiler(object):
|
|||||||
return ret
|
return ret
|
||||||
|
|
||||||
@builds("break")
|
@builds("break")
|
||||||
|
@checkargs(0)
|
||||||
def compile_break_expression(self, expr):
|
def compile_break_expression(self, expr):
|
||||||
ret = ast.Break(lineno=expr.start_line,
|
ret = ast.Break(lineno=expr.start_line,
|
||||||
col_offset=expr.start_column)
|
col_offset=expr.start_column)
|
||||||
@ -1130,6 +1131,7 @@ class HyASTCompiler(object):
|
|||||||
return ret
|
return ret
|
||||||
|
|
||||||
@builds("continue")
|
@builds("continue")
|
||||||
|
@checkargs(0)
|
||||||
def compile_continue_expression(self, expr):
|
def compile_continue_expression(self, expr):
|
||||||
ret = ast.Continue(lineno=expr.start_line,
|
ret = ast.Continue(lineno=expr.start_line,
|
||||||
col_offset=expr.start_column)
|
col_offset=expr.start_column)
|
||||||
|
@ -336,6 +336,13 @@ def test_ast_invalid_for():
|
|||||||
cant_compile("(for* [a 1] (else 1 2))")
|
cant_compile("(for* [a 1] (else 1 2))")
|
||||||
|
|
||||||
|
|
||||||
|
def test_nullary_break_continue():
|
||||||
|
can_compile("(while 1 (break))")
|
||||||
|
cant_compile("(while 1 (break 1))")
|
||||||
|
can_compile("(while 1 (continue))")
|
||||||
|
cant_compile("(while 1 (continue 1))")
|
||||||
|
|
||||||
|
|
||||||
def test_ast_expression_basics():
|
def test_ast_expression_basics():
|
||||||
""" Ensure basic AST expression conversion works. """
|
""" Ensure basic AST expression conversion works. """
|
||||||
code = can_compile("(foo bar)").body[0]
|
code = can_compile("(foo bar)").body[0]
|
||||||
|
Loading…
Reference in New Issue
Block a user