Commit f2c71d24 authored by Robert Bradshaw's avatar Robert Bradshaw

Fix conditional expressions involving references.

Formerly bad code involving unassigned reference temporaries was generated.
parent 670e7f6c
...@@ -10800,6 +10800,8 @@ class CondExprNode(ExprNode): ...@@ -10800,6 +10800,8 @@ class CondExprNode(ExprNode):
def analyse_result_type(self, env): def analyse_result_type(self, env):
self.type = PyrexTypes.independent_spanning_type( self.type = PyrexTypes.independent_spanning_type(
self.true_val.type, self.false_val.type) self.true_val.type, self.false_val.type)
if self.type.is_reference:
self.type = PyrexTypes.CFakeReferenceType(self.type.ref_base_type)
if self.type.is_pyobject: if self.type.is_pyobject:
self.result_ctype = py_object_type self.result_ctype = py_object_type
elif self.true_val.is_ephemeral() or self.false_val.is_ephemeral(): elif self.true_val.is_ephemeral() or self.false_val.is_ephemeral():
......
...@@ -4170,6 +4170,11 @@ def independent_spanning_type(type1, type2): ...@@ -4170,6 +4170,11 @@ def independent_spanning_type(type1, type2):
# whereas "x = True or 2" must evaluate to a type that can hold # whereas "x = True or 2" must evaluate to a type that can hold
# both a boolean value and an integer, so this function works # both a boolean value and an integer, so this function works
# better. # better.
if type1.is_reference ^ type2.is_reference:
if type1.is_reference:
type1 = type1.ref_base_type
else:
type2 = type2.ref_base_type
if type1 == type2: if type1 == type2:
return type1 return type1
elif (type1 is c_bint_type or type2 is c_bint_type) and (type1.is_numeric and type2.is_numeric): elif (type1 is c_bint_type or type2 is c_bint_type) and (type1.is_numeric and type2.is_numeric):
......
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