From: Robert Bradshaw Date: Sat, 11 Sep 2010 21:48:32 +0000 (-0700) Subject: Some error tests for c array iteration. X-Git-Tag: 0.14.alpha0~326 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=7559edf1a14ff70fd0a79116352315b1bfba6ba8;p=cython.git Some error tests for c array iteration. --- diff --git a/Cython/Compiler/Optimize.py b/Cython/Compiler/Optimize.py index 87cf35a9..bc0d4b3c 100644 --- a/Cython/Compiler/Optimize.py +++ b/Cython/Compiler/Optimize.py @@ -306,7 +306,7 @@ class IterationTransform(Visitor.VisitorTransform): else: if not slice_node.type.is_pyobject: - error(slice_node.pos, "Invalid C array iteration") + error(slice_node.pos, "C array iteration requires known end index") return node if start: diff --git a/tests/errors/e_slice.pyx b/tests/errors/e_slice.pyx index 6025cfa9..ead4380f 100644 --- a/tests/errors/e_slice.pyx +++ b/tests/errors/e_slice.pyx @@ -1,10 +1,24 @@ def f(obj2): - cdef int *ptr1 - obj1 = obj2[ptr1::] # error - obj1 = obj2[:ptr1:] # error - obj1 = obj2[::ptr1] # error + cdef int *ptr1 + obj1 = obj2[ptr1::] # error + obj1 = obj2[:ptr1:] # error + obj1 = obj2[::ptr1] # error + +cdef int a +cdef int* int_ptr + +for a in int_ptr: + pass +for a in int_ptr[2:]: + pass +for a in int_ptr[2:2:a]: + pass + _ERRORS = u""" -3:17: Cannot convert 'int *' to Python object -4:18: Cannot convert 'int *' to Python object -5:19: Cannot convert 'int *' to Python object +3:20: Cannot convert 'int *' to Python object +4:21: Cannot convert 'int *' to Python object +5:22: Cannot convert 'int *' to Python object +10:16: C array iteration requires known end index +12:16: C array iteration requires known end index +14:22: C array iteration requires known step size and end index """