diff --git a/hy/compiler.py b/hy/compiler.py index 634ae56..69d307c 100644 --- a/hy/compiler.py +++ b/hy/compiler.py @@ -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*") diff --git a/tests/native_tests/with_decorator.hy b/tests/native_tests/with_decorator.hy index d82214d..2c8e930 100644 --- a/tests/native_tests/with_decorator.hy +++ b/tests/native_tests/with_decorator.hy @@ -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."