Commit a790cb5b authored by Stefan Behnel's avatar Stefan Behnel

make SwitchTransform return True/False as result when Python objects are...

make SwitchTransform return True/False as result when Python objects are requested instead of crashing when trying to cast bint values to PyObject*
parent e939c710
......@@ -1010,14 +1010,14 @@ class SwitchTransform(Visitor.EnvTransform):
result_ref = UtilNodes.ResultRefNode(node)
true_body = Nodes.SingleAssignmentNode(
node.pos,
lhs = result_ref,
rhs = true_val,
first = True)
lhs=result_ref,
rhs=true_val.coerce_to(node.type, self.current_env()),
first=True)
false_body = Nodes.SingleAssignmentNode(
node.pos,
lhs = result_ref,
rhs = false_val,
first = True)
lhs=result_ref,
rhs=false_val.coerce_to(node.type, self.current_env()),
first=True)
if not_in:
true_body, false_body = false_body, true_body
......
......@@ -359,3 +359,39 @@ def int_enum_duplicates_mix(int x):
return 2
else:
return 3
@cython.test_assert_path_exists('//SwitchStatNode')
@cython.test_fail_if_path_exists('//BoolBinopNode', '//PrimaryCmpNode')
def int_in_bool_binop(int x):
"""
>>> int_in_bool_binop(0)
False
>>> int_in_bool_binop(1)
True
>>> int_in_bool_binop(2)
True
>>> int_in_bool_binop(3)
False
"""
return x == 1 or x == 2
@cython.test_assert_path_exists('//SwitchStatNode')
@cython.test_fail_if_path_exists('//BoolBinopNode', '//PrimaryCmpNode')
def int_in_bool_binop_3(int x):
"""
>>> int_in_bool_binop_3(0)
False
>>> int_in_bool_binop_3(1)
True
>>> int_in_bool_binop_3(2)
True
>>> int_in_bool_binop_3(3)
False
>>> int_in_bool_binop_3(4)
True
>>> int_in_bool_binop_3(5)
False
"""
return x == 1 or x == 2 or x == 4
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