Commit 34e5a65a authored by Robert Bradshaw's avatar Robert Bradshaw

Merge pull request #206 from nnemkin/cpp_condexpr_cast_fix

Fix C/C++ compilation error when if/else expression has extension class type.
parents 6b1c2ef1 956316e0
......@@ -9234,6 +9234,8 @@ class CondExprNode(ExprNode):
self.true_val = self.true_val.analyse_types(env)
self.false_val = self.false_val.analyse_types(env)
self.type = PyrexTypes.independent_spanning_type(self.true_val.type, self.false_val.type)
if self.type.is_pyobject:
self.result_ctype = py_object_type
if self.true_val.type.is_pyobject or self.false_val.type.is_pyobject:
self.true_val = self.true_val.coerce_to(self.type, env)
self.false_val = self.false_val.coerce_to(self.type, env)
......
# mode: run
# tag: if_else_expr
# tag: condexpr
cimport cython
cdef class Foo:
cdef dict data
def __repr__(self):
return '<Foo>'
......@@ -14,3 +18,16 @@ cpdef test_type_cast(Foo obj, cond):
<Foo>
"""
return [obj] if cond else obj
cdef func(Foo foo, dict data):
return foo, data
@cython.test_fail_if_path_exists('//PyTypeTestNode')
def test_cpp_pyobject_cast(Foo obj1, Foo obj2, cond):
"""
>>> test_cpp_pyobject_cast(Foo(), Foo(), True)
(<Foo>, None)
"""
return func(obj1 if cond else obj2, obj1.data if cond else obj2.data)
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