Commit d19d6396 authored by Stefan Behnel's avatar Stefan Behnel

fix #442: non-pyobject for-in-loop targets failed with enumerate() optimisation

parent a2bbb8f0
...@@ -237,10 +237,6 @@ class IterationTransform(Visitor.VisitorTransform): ...@@ -237,10 +237,6 @@ class IterationTransform(Visitor.VisitorTransform):
# nothing we can do here, I guess # nothing we can do here, I guess
return node return node
if iterable_target.type is not PyrexTypes.py_object_type:
# this may need conversion, could be made to work
return node
temp = UtilNodes.LetRefNode(ExprNodes.IntNode(enumerate_function.pos, temp = UtilNodes.LetRefNode(ExprNodes.IntNode(enumerate_function.pos,
value='0', value='0',
type=counter_type, type=counter_type,
...@@ -276,6 +272,7 @@ class IterationTransform(Visitor.VisitorTransform): ...@@ -276,6 +272,7 @@ class IterationTransform(Visitor.VisitorTransform):
stats = loop_body) stats = loop_body)
node.target = iterable_target node.target = iterable_target
node.item = node.item.coerce_to(iterable_target.type, self.current_scope)
node.iterator.sequence = enumerate_function.arg_tuple.args[0] node.iterator.sequence = enumerate_function.arg_tuple.args[0]
# recurse into loop to check for further optimisations # recurse into loop to check for further optimisations
......
...@@ -12,7 +12,7 @@ def go_py_enumerate(): ...@@ -12,7 +12,7 @@ def go_py_enumerate():
for i,k in enumerate(range(1,5)): for i,k in enumerate(range(1,5)):
print i, k print i, k
#T442 @cython.test_fail_if_path_exists("//SimpleCallNode//NameNode[@name = 'enumerate']") @cython.test_fail_if_path_exists("//SimpleCallNode//NameNode[@name = 'enumerate']")
def go_c_enumerate(): def go_c_enumerate():
""" """
>>> go_c_enumerate() >>> go_c_enumerate()
...@@ -25,7 +25,7 @@ def go_c_enumerate(): ...@@ -25,7 +25,7 @@ def go_c_enumerate():
for i,k in enumerate(range(1,5)): for i,k in enumerate(range(1,5)):
print i, k print i, k
#T442 @cython.test_fail_if_path_exists("//SimpleCallNode//NameNode[@name = 'enumerate']") @cython.test_fail_if_path_exists("//SimpleCallNode//NameNode[@name = 'enumerate']")
def go_c_enumerate_step(): def go_c_enumerate_step():
""" """
>>> go_c_enumerate_step() >>> go_c_enumerate_step()
...@@ -97,7 +97,7 @@ def py_enumerate_continue(*t): ...@@ -97,7 +97,7 @@ def py_enumerate_continue(*t):
continue continue
print u"::", i, k print u"::", i, k
# T442 @cython.test_fail_if_path_exists("//SimpleCallNode//NameNode[@name = 'enumerate']") @cython.test_fail_if_path_exists("//SimpleCallNode//NameNode[@name = 'enumerate']")
def empty_c_enumerate(): def empty_c_enumerate():
""" """
>>> empty_c_enumerate() >>> empty_c_enumerate()
...@@ -132,7 +132,7 @@ def multi_enumerate(): ...@@ -132,7 +132,7 @@ def multi_enumerate():
for a,(b,(c,d)) in enumerate(enumerate(enumerate(range(1,5)))): for a,(b,(c,d)) in enumerate(enumerate(enumerate(range(1,5)))):
print a,b,c,d print a,b,c,d
# T442 @cython.test_fail_if_path_exists("//SimpleCallNode") @cython.test_fail_if_path_exists("//SimpleCallNode")
def multi_c_enumerate(): def multi_c_enumerate():
""" """
>>> multi_c_enumerate() >>> multi_c_enumerate()
...@@ -145,7 +145,7 @@ def multi_c_enumerate(): ...@@ -145,7 +145,7 @@ def multi_c_enumerate():
for a,(b,(c,d)) in enumerate(enumerate(enumerate(range(1,5)))): for a,(b,(c,d)) in enumerate(enumerate(enumerate(range(1,5)))):
print a,b,c,d print a,b,c,d
# T442 @cython.test_fail_if_path_exists("//SimpleCallNode") @cython.test_fail_if_path_exists("//SimpleCallNode")
def convert_target_enumerate(L): def convert_target_enumerate(L):
""" """
>>> convert_target_enumerate([2,3,5]) >>> convert_target_enumerate([2,3,5])
......
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