From: Dag Sverre Seljebotn Date: Sat, 2 Apr 2011 19:35:11 +0000 (+0200) Subject: Fix #677 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=cc2740ede1e96b0a468e0719511ca6d63cddb930;p=cython.git Fix #677 --- diff --git a/Cython/Compiler/ParseTreeTransforms.py b/Cython/Compiler/ParseTreeTransforms.py index b72b6320..d70dce80 100644 --- a/Cython/Compiler/ParseTreeTransforms.py +++ b/Cython/Compiler/ParseTreeTransforms.py @@ -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 index 00000000..6b858b7b --- /dev/null +++ b/tests/run/cdef_class_field.pyx @@ -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)