Allow fn to have no body
Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
parent
aadf47ed99
commit
74ea8fe5e5
@ -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
|
||||
|
||||
|
@ -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():
|
||||
|
@ -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 []
|
||||
|
Loading…
Reference in New Issue
Block a user