Forbid arguments to break and continue

This commit is contained in:
Kodi Arfer 2017-08-26 11:37:15 -07:00
parent d03b1be686
commit 7ed31a18f3
3 changed files with 11 additions and 0 deletions

2
NEWS
View File

@ -34,6 +34,8 @@ Changes from 0.13.0
* Fixed a crash when `with` suppresses an exception. `with` now returns
`None` in this case.
* `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 ]
* `read`, `read_str`, and `eval` are exposed and documented as top-level

View File

@ -1123,6 +1123,7 @@ class HyASTCompiler(object):
return ret
@builds("break")
@checkargs(0)
def compile_break_expression(self, expr):
ret = ast.Break(lineno=expr.start_line,
col_offset=expr.start_column)
@ -1130,6 +1131,7 @@ class HyASTCompiler(object):
return ret
@builds("continue")
@checkargs(0)
def compile_continue_expression(self, expr):
ret = ast.Continue(lineno=expr.start_line,
col_offset=expr.start_column)

View File

@ -336,6 +336,13 @@ def test_ast_invalid_for():
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():
""" Ensure basic AST expression conversion works. """
code = can_compile("(foo bar)").body[0]