summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Bradshaw <robertwb@gmail.com>2014-10-07 21:24:00 -0700
committerRobert Bradshaw <robertwb@gmail.com>2014-10-07 21:24:00 -0700
commit95228cfe420f39cd69844268dee123a324435ff8 (patch)
tree829a7144858238d41dbe37696b6fcb0861045ff1
parente1d36b1d300be23f4e663bbb29896b0b33c7d171 (diff)
downloadcython-95228cfe420f39cd69844268dee123a324435ff8.tar.gz
Infer pointer type for array assignment.
-rw-r--r--Cython/Compiler/TypeInference.py4
-rw-r--r--tests/run/type_inference.pyx14
2 files changed, 18 insertions, 0 deletions
diff --git a/Cython/Compiler/TypeInference.py b/Cython/Compiler/TypeInference.py
index 10b88d2a2..647189ad7 100644
--- a/Cython/Compiler/TypeInference.py
+++ b/Cython/Compiler/TypeInference.py
@@ -502,6 +502,8 @@ def aggressive_spanning_type(types, might_overflow, pos):
result_type = result_type.const_base_type
if result_type.is_cpp_class:
result_type.check_nullary_constructor(pos)
+ if result_type.is_array:
+ result_type = PyrexTypes.c_ptr_type(result_type.base_type)
return result_type
def safe_spanning_type(types, might_overflow, pos):
@@ -512,6 +514,8 @@ def safe_spanning_type(types, might_overflow, pos):
result_type = result_type.ref_base_type
if result_type.is_cpp_class:
result_type.check_nullary_constructor(pos)
+ if result_type.is_array:
+ result_type = PyrexTypes.c_ptr_type(result_type.base_type)
if result_type.is_pyobject:
# In theory, any specific Python type is always safe to
# infer. However, inferring str can cause some existing code
diff --git a/tests/run/type_inference.pyx b/tests/run/type_inference.pyx
index dba4c4ec3..ee1aeb926 100644
--- a/tests/run/type_inference.pyx
+++ b/tests/run/type_inference.pyx
@@ -495,6 +495,20 @@ def safe_c_functions():
assert 2 == f(1)
@infer_types(None)
+def ptr_types():
+ """
+ >>> ptr_types()
+ """
+ cdef int a
+ a_ptr = &a
+ assert typeof(a_ptr) == "int *", typeof(a_ptr)
+ a_ptr_ptr = &a_ptr
+ assert typeof(a_ptr_ptr) == "int **", typeof(a_ptr_ptr)
+ cdef int[1] b
+ b_ref = b
+ assert typeof(b_ref) == "int *", typeof(b_ref)
+
+@infer_types(None)
def args_tuple_keywords(*args, **kwargs):
"""
>>> args_tuple_keywords(1,2,3, a=1, b=2)