Commit 2352daa6 authored by Stefan Behnel's avatar Stefan Behnel

fix for ticket 232: remember result type when calling an extension type

--HG--
rename : tests/bugs/ext_instance_type_T232.pyx => tests/run/ext_instance_type_T232.pyx
parent 545a832d
...@@ -1074,8 +1074,8 @@ class NameNode(AtomicNewTempExprNode): ...@@ -1074,8 +1074,8 @@ class NameNode(AtomicNewTempExprNode):
# Reference to a local or global variable name. # Reference to a local or global variable name.
# #
# name string Python name of the variable # name string Python name of the variable
#
# entry Entry Symbol table entry # entry Entry Symbol table entry
# type_entry Entry For extension type names, the original type entry
is_name = True is_name = True
is_cython_module = False is_cython_module = False
...@@ -1083,6 +1083,7 @@ class NameNode(AtomicNewTempExprNode): ...@@ -1083,6 +1083,7 @@ class NameNode(AtomicNewTempExprNode):
lhs_of_first_assignment = False lhs_of_first_assignment = False
is_used_as_rvalue = 0 is_used_as_rvalue = 0
entry = None entry = None
type_entry = None
def create_analysed_rvalue(pos, env, entry): def create_analysed_rvalue(pos, env, entry):
node = NameNode(pos) node = NameNode(pos)
...@@ -1227,10 +1228,12 @@ class NameNode(AtomicNewTempExprNode): ...@@ -1227,10 +1228,12 @@ class NameNode(AtomicNewTempExprNode):
self.type = type self.type = type
def check_identifier_kind(self): def check_identifier_kind(self):
#print "NameNode.check_identifier_kind:", self.entry.name ### # Check that this is an appropriate kind of name for use in an
#print self.entry.__dict__ ### # expression. Also finds the variable entry associated with
# an extension type.
entry = self.entry entry = self.entry
#entry.used = 1 if entry.is_type and entry.type.is_extension_type:
self.type_entry = entry
if not (entry.is_const or entry.is_variable if not (entry.is_const or entry.is_variable
or entry.is_builtin or entry.is_cfunction): or entry.is_builtin or entry.is_cfunction):
if self.entry.as_variable: if self.entry.as_variable:
...@@ -2323,6 +2326,13 @@ class SimpleCallNode(CallNode): ...@@ -2323,6 +2326,13 @@ class SimpleCallNode(CallNode):
self.arg_tuple = TupleNode(self.pos, args = self.args) self.arg_tuple = TupleNode(self.pos, args = self.args)
self.arg_tuple.analyse_types(env) self.arg_tuple.analyse_types(env)
self.args = None self.args = None
if function.is_name and function.type_entry:
# We are calling an extension type constructor. As
# long as we do not support __new__(), the result type
# is clear
self.type = function.type_entry.type
self.result_ctype = py_object_type
else:
self.type = py_object_type self.type = py_object_type
self.is_temp = 1 self.is_temp = 1
else: else:
...@@ -2586,6 +2596,12 @@ class GeneralCallNode(CallNode): ...@@ -2586,6 +2596,12 @@ class GeneralCallNode(CallNode):
if self.starstar_arg: if self.starstar_arg:
self.starstar_arg = \ self.starstar_arg = \
self.starstar_arg.coerce_to_pyobject(env) self.starstar_arg.coerce_to_pyobject(env)
if function.is_name and function.type_entry:
# We are calling an extension type constructor. As long
# as we do not support __new__(), the result type is clear
self.type = function.type_entry.type
self.result_ctype = py_object_type
else:
self.type = py_object_type self.type = py_object_type
self.is_temp = 1 self.is_temp = 1
......
__doc__ = u""" __doc__ = u"""
>>> set_attr(5) >>> set_attr(5)
>>> get_attr() >>> get_attr()
None
""" """
cdef class MyExt: cdef class MyExt:
......
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