From 74ea8fe5e5124a1ff2848056f591fed32ff35950 Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Fri, 19 Apr 2013 18:31:32 -0700 Subject: [PATCH] Allow fn to have no body Signed-off-by: Julien Danjou --- hy/compiler.py | 2 +- tests/compilers/test_ast.py | 2 ++ tests/native_tests/language.hy | 4 +++- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/hy/compiler.py b/hy/compiler.py index 19a68df..14c33ed 100644 --- a/hy/compiler.py +++ b/hy/compiler.py @@ -1027,7 +1027,7 @@ class HyASTCompiler(object): col_offset=expr.start_column) @builds("fn") - @checkargs(min=2) + @checkargs(min=1) def compile_fn_expression(self, expression): expression.pop(0) # fn diff --git a/tests/compilers/test_ast.py b/tests/compilers/test_ast.py index 3b34e14..c565046 100644 --- a/tests/compilers/test_ast.py +++ b/tests/compilers/test_ast.py @@ -300,6 +300,8 @@ def test_ast_anon_fns_basics(): """ Ensure anon fns work. """ code = hy_compile(tokenize("(fn (x) (* x x))")).body[0] assert type(code) == ast.FunctionDef + code = hy_compile(tokenize("(fn (x))")).body[0] + cant_compile("(fn)") def test_ast_non_decoratable(): diff --git a/tests/native_tests/language.hy b/tests/native_tests/language.hy index 1480d94..b902526 100644 --- a/tests/native_tests/language.hy +++ b/tests/native_tests/language.hy @@ -474,7 +474,9 @@ (defn test-fn-return [] "NATIVE: test function return" (setv fn-test ((fn [] (fn [] (+ 1 1))))) - (assert (= (fn-test) 2))) + (assert (= (fn-test) 2)) + (setv fn-test (fn [])) + (assert (= (fn-test) None))) (defn test-let []