Fix #677
authorDag Sverre Seljebotn <dagss@student.matnat.uio.no>
Sat, 2 Apr 2011 19:35:11 +0000 (21:35 +0200)
committerDag Sverre Seljebotn <dagss@student.matnat.uio.no>
Sat, 2 Apr 2011 19:35:11 +0000 (21:35 +0200)
Cython/Compiler/ParseTreeTransforms.py
tests/run/cdef_class_field.pyx [new file with mode: 0644]

index b72b6320054ad4a6509355ab4a4bfc222e908eca..d70dce805ba0295495405f614a4c5e4b61e7b0d4 100644 (file)
@@ -1253,7 +1253,8 @@ if VALUE is not None:
     def visit_CNameDeclaratorNode(self, node):
         if node.name in self.seen_vars_stack[-1]:
             entry = self.env_stack[-1].lookup(node.name)
-            if entry is None or entry.visibility != 'extern':
+            if (entry is None or entry.visibility != 'extern'
+                and not entry.scope.is_c_class_scope):
                 warning(node.pos, "cdef variable '%s' declared after it is used" % node.name, 2)
         self.visitchildren(node)
         return node
diff --git a/tests/run/cdef_class_field.pyx b/tests/run/cdef_class_field.pyx
new file mode 100644 (file)
index 0000000..6b858b7
--- /dev/null
@@ -0,0 +1,19 @@
+# mode: run
+# tag: cdefclass, #677
+"""
+>>> str(Foo(4))
+'4'
+>>> x
+3
+"""
+
+x = 3
+cdef int y
+
+cdef class Foo:
+    cdef int x
+    cdef int y
+    def __init__(self, x):
+        self.x = x
+    def __str__(self):
+        return str(self.x)