Commit b33a60bc authored by Mark Florisson's avatar Mark Florisson

Fix cascaded assignment bug with builtin call as rhs

parent be9677c8
......@@ -9144,6 +9144,42 @@ class CoerceToTempNode(CoercionNode):
code.put_incref_memoryviewslice(self.result(),
not self.in_nogil_context)
class ProxyNode(CoercionNode):
"""
A node that should not be replaced by transforms or other means,
and hence can be useful to wrap the argument to a clone node
MyNode -> ProxyNode -> ArgNode
CloneNode -^
"""
def __init__(self, arg):
super(ProxyNode, self).__init__(arg)
self.type = arg.type
def generate_result_code(self, code):
self.arg.generate_result_code(code)
def result(self):
return self.arg.result()
def is_simple(self):
return self.arg.is_simple()
def may_be_none(self):
return self.arg.may_be_none()
def generate_evaluation_code(self, code):
self.arg.generate_evaluation_code(code)
def generate_result_code(self, code):
self.arg.generate_result_code(code)
def generate_disposal_code(self, code):
self.arg.generate_disposal_code(code)
def free_temps(self, code):
self.arg.free_temps(code)
class CloneNode(CoercionNode):
# This node is employed when the result of another node needs
......
......@@ -4813,13 +4813,16 @@ class CascadedAssignmentNode(AssignmentNode):
lhs.analyse_target_declaration(env)
def analyse_types(self, env, use_temp = 0):
from ExprNodes import CloneNode, ProxyNode
self.rhs.analyse_types(env)
if not self.rhs.is_simple():
if use_temp:
self.rhs = self.rhs.coerce_to_temp(env)
else:
self.rhs = self.rhs.coerce_to_simple(env)
from ExprNodes import CloneNode
self.rhs = ProxyNode(self.rhs)
self.coerced_rhs_list = []
for lhs in self.lhs_list:
lhs.analyse_target_types(env)
......
import cython
def test_cascaded_assignment_simple():
"""
>>> test_cascaded_assignment_simple()
5
"""
a = b = c = 5
return a
def test_cascaded_assignment_typed():
"""
>>> test_cascaded_assignment_typed()
int Python object double
(5, 5, 5.0)
"""
cdef int a
cdef object b
cdef double c
a = b = c = 5
print cython.typeof(a), cython.typeof(b), cython.typeof(c)
return a, b, c
def test_cascaded_assignment_builtin_expr():
"""
This test is useful as previously the rhs expr node got replaced resulting
in CloneNode generating None in the C source.
>>> test_cascaded_assignment_builtin_expr()
(10.0, 10.0, 10.0)
"""
a = b = c = float(10)
return a, b, c
def expr():
print "expr called"
return 10
def test_cascaded_assignment_evaluate_expr():
"""
>>> test_cascaded_assignment_evaluate_expr()
expr called
(10.0, 10.0, 10.0)
"""
a = b = c = float(expr())
return a, b, c
def test():
"""
>>> test()
5
"""
a = b = c = 5
return a
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