diff --git a/NEWS b/NEWS index 051975f..429d69c 100644 --- a/NEWS +++ b/NEWS @@ -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 diff --git a/hy/compiler.py b/hy/compiler.py index 6781df6..5b2dfa8 100755 --- a/hy/compiler.py +++ b/hy/compiler.py @@ -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) diff --git a/tests/compilers/test_ast.py b/tests/compilers/test_ast.py index b5d4860..4e0e00b 100644 --- a/tests/compilers/test_ast.py +++ b/tests/compilers/test_ast.py @@ -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]