Merge pull request #753 from Tritlo/issue752

Added a fix for nested decorators. Fixes #752
This commit is contained in:
Morten Linderud 2015-01-14 22:10:12 +01:00
commit 7829b8752c
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."