diff --git a/hy/core/macros.hy b/hy/core/macros.hy index 6a8709f..fc296a8 100644 --- a/hy/core/macros.hy +++ b/hy/core/macros.hy @@ -98,6 +98,8 @@ (for* [y bar] baz))" (setv body (list body)) + (if (empty? body) + (macro-error None "`for' requires a body to evaluate")) (setv lst (get body -1)) (setv belse (if (and (isinstance lst HyExpression) (= (get lst 0) "else")) [(body.pop)] diff --git a/tests/compilers/test_ast.py b/tests/compilers/test_ast.py index 0fe320e..4491f83 100644 --- a/tests/compilers/test_ast.py +++ b/tests/compilers/test_ast.py @@ -484,7 +484,7 @@ def test_for_compile_error(): assert(False) try: - can_compile("(fn [] (for [x]))") + can_compile("(fn [] (for [x] x))") except HyTypeError as e: assert(e.message == "`for' requires an even number of args.") else: @@ -497,6 +497,13 @@ def test_for_compile_error(): else: assert(False) + try: + can_compile("(fn [] (for [x xx] (else 1)))") + except HyTypeError as e: + assert(e.message == "`for' requires a body to evaluate") + else: + assert(False) + def test_attribute_access(): """Ensure attribute access compiles correctly"""