Commit 03ea3932 authored by Stefan Behnel's avatar Stefan Behnel

fix type inference for names of builtin functions

parent 6cf6fc66
......@@ -1349,8 +1349,12 @@ class NameNode(AtomicExprNode):
# is used for the pointer to the type they represent.
return type_type
elif self.entry.type.is_cfunction:
# special case: referring to a C function must return its pointer
return PyrexTypes.CPtrType(self.entry.type)
if self.entry.scope.is_builtin_scope:
# special case: optimised builtin functions must be treated as Python objects
return py_object_type
else:
# special case: referring to a C function must return its pointer
return PyrexTypes.CPtrType(self.entry.type)
else:
return self.entry.type
......
......@@ -12,6 +12,15 @@ max_long_long = 2 ** (sizeof(long long) * 8 - 1) - 1
cimport cython
def abs_as_name():
"""
>>> _abs = abs_as_name()
>>> _abs(-5)
5
"""
x = abs
return x
def py_abs(a):
"""
>>> py_abs(-5)
......
......@@ -221,6 +221,24 @@ def c_functions():
assert typeof(f) == 'int (*)(int)', typeof(f)
assert 2 == f(1)
def builtin_functions():
"""
>>> _abs, _getattr = builtin_functions()
Python object
Python object
>>> _abs(-1)
1
>>> class o(object): pass
>>> o.x = 1
>>> _getattr(o, 'x')
1
"""
_abs = abs
print(typeof(_abs))
_getattr = getattr
print(typeof(_getattr))
return _abs, _getattr
def cascade():
"""
>>> cascade()
......
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