Commit e4742fe3 authored by Stefan Behnel's avatar Stefan Behnel

fix bug #544: handle side-effects in flattened in-list tests correctly

parent 0d04f2bb
......@@ -803,7 +803,12 @@ class FlattenInListTransform(Visitor.VisitorTransform, SkipDeclarations):
lhs = UtilNodes.ResultRefNode(node.operand1)
conds = []
temps = []
for arg in args:
if not arg.is_simple():
# must evaluate all non-simple RHS before doing the comparisons
arg = UtilNodes.LetRefNode(arg)
temps.append(arg)
cond = ExprNodes.PrimaryCmpNode(
pos = node.pos,
operand1 = lhs,
......@@ -822,7 +827,10 @@ class FlattenInListTransform(Visitor.VisitorTransform, SkipDeclarations):
operand2 = right)
condition = reduce(concat, conds)
return UtilNodes.EvalWithTempExprNode(lhs, condition)
new_node = UtilNodes.EvalWithTempExprNode(lhs, condition)
for temp in temps[::-1]:
new_node = UtilNodes.EvalWithTempExprNode(temp, new_node)
return new_node
visit_Node = Visitor.VisitorTransform.recurse_to_children
......
def count(i=[0]):
i[0] += 1
return i[0]
def test(x):
"""
>>> def py_count(i=[0]):
... i[0] += 1
... return i[0]
>>> 1 in (py_count(), py_count(), py_count(), py_count())
True
>>> 4 in (py_count(), py_count(), py_count(), py_count())
False
>>> 12 in (py_count(), py_count(), py_count(), py_count())
True
>>> test(1)
True
>>> test(4)
False
>>> test(12)
True
"""
return x in (count(), count(), count(), count())
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