Commit bd50b09a authored by Vitja Makarov's avatar Vitja Makarov

Remove dict items that can't be represented as PyObject after type inference

parent 33e78f15
......@@ -6724,17 +6724,33 @@ class GlobalsExprNode(AtomicExprNode):
code.put_gotref(self.result())
class LocalsDictItemNode(DictItemNode):
def analyse_types(self, env):
self.key.analyse_types(env)
self.value.analyse_types(env)
self.key = self.key.coerce_to_pyobject(env)
if self.value.type.can_coerce_to_pyobject(env):
self.value = self.value.coerce_to_pyobject(env)
else:
self.value = None
class FuncLocalsExprNode(DictNode):
def __init__(self, pos, env):
local_vars = [entry.name for entry in env.entries.values()
if entry.name and (entry.type is unspecified_type or
entry.type.can_coerce_to_pyobject(env))]
items = [DictItemNode(pos, key=IdentifierStringNode(pos, value=var),
value=NameNode(pos, name=var, allow_null=True))
if entry.name]
items = [LocalsDictItemNode(
pos, key=IdentifierStringNode(pos, value=var),
value=NameNode(pos, name=var, allow_null=True))
for var in local_vars]
DictNode.__init__(self, pos, key_value_pairs=items,
exclude_null_values=True)
def analyse_types(self, env):
super(FuncLocalsExprNode, self).analyse_types(env)
self.key_value_pairs = [i for i in self.key_value_pairs
if i.value is not None]
class PyClassLocalsExprNode(AtomicExprNode):
def __init__(self, pos, pyclass_dict):
......
......@@ -79,3 +79,12 @@ def locals_ctype():
"""
cdef int *p = NULL
return 'p' in locals()
def locals_ctype_inferred():
"""
>>> locals_ctype_inferred()
False
"""
cdef int *p = NULL
b = p
return 'b' in locals()
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