Commit 7d69ae07 authored by da-woods's avatar da-woods Committed by Stefan Behnel

Don't crash when probing type of cimported module (GH-4001)

Closes https://github.com/cython/cython/issues/4000
parent 921cd966
......@@ -6049,7 +6049,7 @@ class PyMethodCallNode(SimpleCallNode):
# not an attribute itself, but might have been assigned from one (e.g. bound method)
for assignment in self.function.cf_state:
value = assignment.rhs
if value and value.is_attribute and value.obj.type.is_pyobject:
if value and value.is_attribute and value.obj.type and value.obj.type.is_pyobject:
if attribute_is_likely_method(value):
likely_method = 'likely'
break
......@@ -6851,7 +6851,11 @@ class AttributeNode(ExprNode):
# FIXME: this is way too redundant with analyse_types()
node = self.analyse_as_cimported_attribute_node(env, target=False)
if node is not None:
return node.entry.type
if node.entry.type and node.entry.type.is_cfunction:
# special-case - function converted to pointer
return PyrexTypes.CPtrType(node.entry.type)
else:
return node.entry.type
node = self.analyse_as_type_attribute(env)
if node is not None:
return node.entry.type
......
......@@ -41,6 +41,8 @@ ctypedef int my_int
######## a.pyx ########
from other cimport (
A,
foo,
......@@ -48,9 +50,19 @@ from other cimport (
print A, foo(10)
cimport other
print other.A, other.foo(10)
cdef call_fooptr(int (*fptr)(int)):
return fptr(10)
def call_other_foo():
x = other.foo # GH4000 - failed because other was untyped
return call_fooptr(x) # check that x is correctly resolved as a function pointer
print(other.A, other.foo(10), call_other_foo())
from pkg cimport sub
cdef sub.my_int a = 100
from pkg.subpkg cimport submod
\ No newline at end of file
from pkg.subpkg cimport submod
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