From 1d5b4554917e52195a5b08dc3226cb8464da0f81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matth=C3=ADas=20P=C3=A1ll=20Gissurarson?= Date: Wed, 14 Jan 2015 19:42:02 +0000 Subject: [PATCH] Added a fix for nested decorators. Fixes #752 --- hy/compiler.py | 2 +- tests/native_tests/with_decorator.hy | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) 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."