Commit f9483650 authored by Vitja Makarov's avatar Vitja Makarov

CF fix for defnodes and classes

parent 5ba30c45
......@@ -583,6 +583,10 @@ class CreateControlFlowGraph(CythonTransform):
return node
def visit_FuncDefNode(self, node):
for arg in node.args:
if arg.default:
self.visitchildren(arg)
self.visitchildren(node, attrs=('decorators',))
self.env_stack.append(self.env)
self.env = node.local_scope
self.stack.append(self.flow)
......@@ -597,6 +601,8 @@ class CreateControlFlowGraph(CythonTransform):
# Function body block
self.flow.nextblock()
for arg in node.args:
self.visit(arg)
if node.star_arg:
self.flow.mark_argument(node.star_arg,
TypedExprNode(Builtin.tuple_type,
......@@ -607,7 +613,7 @@ class CreateControlFlowGraph(CythonTransform):
TypedExprNode(Builtin.dict_type,
may_be_none=False),
node.starstar_arg.entry)
self.visitchildren(node)
self.visit(node.body)
# Workaround for generators
if node.is_generator:
self.visit(node.gbody.body)
......@@ -1105,15 +1111,14 @@ class CreateControlFlowGraph(CythonTransform):
return node
def visit_PyClassDefNode(self, node):
self.flow.mark_assignment(node.target,
object_expr_not_none, self.env.lookup(node.name))
# TODO: add negative attribute list to "visitchildren"?
self.visitchildren(node, attrs=['dict', 'metaclass',
'mkw', 'bases', 'classobj'])
self.visitchildren(node, attrs=('dict', 'metaclass',
'mkw', 'bases', 'class_result'))
self.flow.mark_assignment(node.target, object_expr_not_none,
self.env.lookup(node.name))
self.env_stack.append(self.env)
self.env = node.scope
self.flow.nextblock()
self.visitchildren(node, attrs=['body'])
self.visitchildren(node, attrs=('body',))
self.flow.nextblock()
self.env = self.env_stack.pop()
return node
......
......@@ -74,6 +74,44 @@ def raise_stat():
exc = ValueError
msg = 'dummy'
def defnode_decorator():
@decorator
def foo():
pass
def decorator():
pass
def defnode_default():
def foo(arg=default()):
pass
def default():
pass
def class_bases():
class foo(bar):
pass
class bar(object):
pass
def class_decorators():
@decorator
class foo(object):
pass
def decorator(cls):
return cls
def class_py3k_metaclass():
class foo(metaclass=Meta):
pass
class Meta(object):
pass
def class_py3k_args():
class foo(*args, **kwargs):
pass
args = []
kwargs = {}
_ERRORS = """
6:11: local variable 'a' referenced before assignment
12:12: local variable 'a' might be referenced before assignment
......@@ -85,4 +123,11 @@ _ERRORS = """
66:13: local variable 'foo' referenced before assignment
71:17: local variable 'exc' referenced before assignment
71:22: local variable 'msg' referenced before assignment
78:4: local variable 'decorator' referenced before assignment
85:23: local variable 'default' referenced before assignment
91:17: local variable 'bar' referenced before assignment
97:4: local variable 'decorator' referenced before assignment
104:28: local variable 'Meta' referenced before assignment
110:19: local variable 'args' referenced before assignment
110:29: local variable 'kwargs' referenced before assignment
"""
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment