From 7fffc572559d5d2b889af747f083f5dad16645f9 Mon Sep 17 00:00:00 2001 From: ben Date: Sat, 6 Apr 2019 12:46:48 +1300 Subject: [PATCH] Fix decorator on functions with defaults --- tests/snippets/decorators.py | 10 ++++++++++ vm/src/compile.rs | 5 +++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/tests/snippets/decorators.py b/tests/snippets/decorators.py index fcc196f93..2633308f1 100644 --- a/tests/snippets/decorators.py +++ b/tests/snippets/decorators.py @@ -15,6 +15,16 @@ c = add(10, 3) assert c == 14 +@logged +def add3(a, b, c=2): + return a + b + c + + +d = add3(12, 5) + +assert d == 20 + + def f(func): return lambda: 42 class A: pass a = A() diff --git a/vm/src/compile.rs b/vm/src/compile.rs index 88818f52f..d7f774b83 100644 --- a/vm/src/compile.rs +++ b/vm/src/compile.rs @@ -585,6 +585,9 @@ impl Compiler { let was_in_function_def = self.in_function_def; self.in_loop = false; self.in_function_def = true; + + self.prepare_decorators(decorator_list)?; + let mut flags = self.enter_function(name, args)?; let (new_body, doc_str) = get_doc(body); @@ -598,8 +601,6 @@ impl Compiler { self.emit(Instruction::ReturnValue); let code = self.pop_code_object(); - self.prepare_decorators(decorator_list)?; - // Prepare type annotations: let mut num_annotations = 0;