Added a fix for nested decorators. Fixes #752

This commit is contained in:
Matthías Páll Gissurarson 2015-01-14 19:42:02 +00:00
parent 19b55384f8
commit 1d5b455491
2 changed files with 10 additions and 1 deletions

View File

@ -1295,7 +1295,7 @@ class HyASTCompiler(object):
isinstance(fn.stmts[-1], ast.ClassDef)):
raise HyTypeError(expr, "Decorated a non-function")
decorators, ret, _ = self._compile_collect(expr)
fn.stmts[-1].decorator_list = decorators
fn.stmts[-1].decorator_list = decorators + fn.stmts[-1].decorator_list
return ret + fn
@builds("with*")

View File

@ -15,6 +15,15 @@
(defclass cls []
[[my_attr 456]]))
(defn test-decorator-clobbing []
"NATIVE: Tests whether nested decorators work"
(do
(defn dec1 [f] (defn k [] (+ (f) 1)))
(defn dec2 [f] (defn k [] (+ (f) 2)))
(with-decorator dec1
(with-decorator dec2
(defn f [] 1)))
(assert (= (f) 4))))
(defn test-decorators []
"NATIVE: test decorators."