Commit 554f5e50 authored by Stefan Behnel's avatar Stefan Behnel

GH-2919: Prevent tuple constants that compare equal but have different item...

GH-2919: Prevent tuple constants that compare equal but have different item types from being merged into one.
parent 0830ddf4
......@@ -198,11 +198,13 @@ def make_dedup_key(outer_type, item_nodes):
@return: A tuple that can be used as a dict key for deduplication.
"""
item_keys = [
(py_object_type, None) if node is None
(py_object_type, None, type(None)) if node is None
# For sequences and their "mult_factor", see TupleNode.
else make_dedup_key(node.type, [node.mult_factor if node.is_literal else None] + node.args) if node.is_sequence_constructor
else make_dedup_key(node.type, (node.start, node.stop, node.step)) if node.is_slice
else (node.type, node.constant_result) if node.has_constant_result()
# For constants, look at the Python value type if we don't know the concrete Cython type.
else (node.type, node.constant_result,
type(node.constant_result) if node.type is py_object_type else None) if node.has_constant_result()
else None # something we cannot handle => short-circuit below
for node in item_nodes
]
......@@ -1207,6 +1209,10 @@ class BoolNode(ConstNode):
return str(int(self.value))
def coerce_to(self, dst_type, env):
if dst_type == self.type:
return self
if dst_type is py_object_type and self.type is Builtin.bool_type:
return self
if dst_type.is_pyobject and self.type.is_int:
return BoolNode(
self.pos, value=self.value,
......
......@@ -132,3 +132,17 @@ def return_nonconstant_tuple():
"""
a = eval("1")
return ('a', a, 'd')
def constant_types_comparing_equal():
"""
>>> constant_types_comparing_equal()
((False, False), (0, 0), (0.0, 0.0), (0, False), (False, 0.0), (0, 0.0))
"""
bint_tuple= (False, False)
int_tuple = (0, 0)
float_tuple = (0.0, 0.0)
int_bool = (0, False)
bool_float = (False, 0.0)
int_float = (0, 0.0)
return bint_tuple, int_tuple, float_tuple, int_bool, bool_float, int_float
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