Commit 20108dcd authored by Stefan Behnel's avatar Stefan Behnel

fix sequence assignments for value coercion to non-Python types

- coercion code cannot currently be taken out of the conditional as the temp release of the coercion code happens straight away
parent 40002217
...@@ -2793,7 +2793,10 @@ class SequenceNode(ExprNode): ...@@ -2793,7 +2793,10 @@ class SequenceNode(ExprNode):
item.result(), item.result(),
i)) i))
code.put_incref(item.result(), item.ctype()) code.put_incref(item.result(), item.ctype())
value_node = self.coerced_unpacked_items[i]
value_node.generate_evaluation_code(code)
rhs.generate_disposal_code(code) rhs.generate_disposal_code(code)
code.putln("} else {") code.putln("} else {")
code.putln( code.putln(
...@@ -2811,6 +2814,8 @@ class SequenceNode(ExprNode): ...@@ -2811,6 +2814,8 @@ class SequenceNode(ExprNode):
item.result(), item.result(),
typecast(item.ctype(), py_object_type, unpack_code), typecast(item.ctype(), py_object_type, unpack_code),
code.error_goto_if_null(item.result(), self.pos))) code.error_goto_if_null(item.result(), self.pos)))
value_node = self.coerced_unpacked_items[i]
value_node.generate_evaluation_code(code)
code.put_error_if_neg(self.pos, code.put_error_if_neg(self.pos,
"__Pyx_EndUnpack(%s)" % ( "__Pyx_EndUnpack(%s)" % (
self.iterator.py_result())) self.iterator.py_result()))
...@@ -2821,9 +2826,8 @@ class SequenceNode(ExprNode): ...@@ -2821,9 +2826,8 @@ class SequenceNode(ExprNode):
code.putln("}") code.putln("}")
for i in range(len(self.args)): for i in range(len(self.args)):
value_node = self.coerced_unpacked_items[i] self.args[i].generate_assignment_code(
value_node.generate_evaluation_code(code) self.coerced_unpacked_items[i], code)
self.args[i].generate_assignment_code(value_node, code)
def annotate(self, code): def annotate(self, code):
for arg in self.args: for arg in self.args:
......
...@@ -3,19 +3,41 @@ __doc__ = u""" ...@@ -3,19 +3,41 @@ __doc__ = u"""
(1, 2, 3) (1, 2, 3)
>>> assign3(t) >>> assign3(t)
(1, 2, 3) (1, 2, 3)
>>> >>> assign3_int(l)
(1, 2, 3)
>>> assign3_mixed1(l)
(1, 2, 3)
>>> assign3_mixed2(l)
(1, 2, 3)
>>> assign3_mixed3(l)
(1, 2, 3)
>>> a,b = 99,99 >>> a,b = 99,98
>>> a,b = t >>> a,b = t
Traceback (most recent call last): Traceback (most recent call last):
ValueError: too many values to unpack ValueError: too many values to unpack
>>> a,b >>> a,b
(99, 99) (99, 98)
>>> test_overwrite(l) >>> test_overwrite(l)
(99, 99) (99, 98)
>>> test_overwrite(t) >>> test_overwrite(t)
(99, 99) (99, 98)
>>> test_overwrite_int(l)
(99, 98)
>>> test_overwrite_int(t)
(99, 98)
>>> test_overwrite_mixed(l)
(99, 98)
>>> test_overwrite_mixed(t)
(99, 98)
>>> test_overwrite_mixed2(l)
(99, 98)
>>> test_overwrite_mixed2(t)
(99, 98)
""" """
t = (1,2,3) t = (1,2,3)
...@@ -25,8 +47,60 @@ def assign3(t): ...@@ -25,8 +47,60 @@ def assign3(t):
a,b,c = t a,b,c = t
return (a,b,c) return (a,b,c)
def assign3_int(t):
cdef int a,b,c
a,b,c = t
return (a,b,c)
def assign3_mixed1(t):
cdef int a
a,b,c = t
return (a,b,c)
def assign3_mixed2(t):
cdef int b
a,b,c = t
return (a,b,c)
def assign3_mixed3(t):
cdef int c
a,b,c = t
return (a,b,c)
def assign3_mixed4(t):
cdef int b,c
a,b,c = t
return (a,b,c)
def test_overwrite(t): def test_overwrite(t):
a,b = 99,99 a,b = 99,98
try:
a,b = t
except ValueError:
pass
return (a,b)
def test_overwrite_int(t):
cdef int a,b
a,b = 99,98
try:
a,b = t
except ValueError:
pass
return (a,b)
def test_overwrite_mixed(t):
cdef int b
a,b = 99,98
try:
a,b = t
except ValueError:
pass
return (a,b)
def test_overwrite_mixed2(t):
cdef int a
a,b = 99,98
try: try:
a,b = t a,b = t
except ValueError: except ValueError:
......
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