fix cdef @locals with default arguments
authorHaoyu Bai <baihaoyu@gmail.com>
Thu, 7 Apr 2011 12:55:35 +0000 (20:55 +0800)
committerHaoyu Bai <baihaoyu@gmail.com>
Thu, 7 Apr 2011 13:23:13 +0000 (21:23 +0800)
Cython/Compiler/Nodes.py
tests/run/cdef_locals_decorator_T477.pyx

index a8ed64e67f119c4df0b99c675a079633662f8bcb..b8f94ceebf0eae54f1f53d4f81c82cdd7aa12a22 100644 (file)
@@ -1673,7 +1673,12 @@ class CFuncDefNode(FuncDefNode):
         self.directive_locals.update(env.directives['locals'])
         base_type = self.base_type.analyse(env)
         # The 2 here is because we need both function and argument names.
-        name_declarator, type = self.declarator.analyse(base_type, env, nonempty = 2 * (self.body is not None))
+        if isinstance(self.declarator, CFuncDeclaratorNode):
+            name_declarator, type = self.declarator.analyse(base_type, env,
+                                                            nonempty = 2 * (self.body is not None),
+                                                            directive_locals = self.directive_locals)
+        else:
+            name_declarator, type = self.declarator.analyse(base_type, env, nonempty = 2 * (self.body is not None))
         if not type.is_cfunction:
             error(self.pos,
                 "Suite attached to non-function declaration")
index c495fc91b8cb8e8cef7cf181176713a0a4a8ba7e..617f011a8fc6118c55d65e88b6c4b9a83a9e2584 100644 (file)
@@ -5,6 +5,10 @@ import cython
 cdef func(x):
     return x**2
 
+@cython.locals(x=double)
+cdef func_defval(x=0):
+    return x**2
+
 def test():
     """
     >>> isinstance(test(), float)