Commit 02864e44 authored by Stefan Behnel's avatar Stefan Behnel

fix bug #693: side effects on complex coercion

parent 07e4c33c
......@@ -7563,10 +7563,14 @@ class CoerceToPyTypeNode(CoercionNode):
is_temp = 1
def __init__(self, arg, env, type=py_object_type):
CoercionNode.__init__(self, arg)
if not arg.type.create_to_py_utility_code(env):
error(arg.pos,
"Cannot convert '%s' to Python object" % arg.type)
error(arg.pos, "Cannot convert '%s' to Python object" % arg.type)
elif arg.type.is_complex:
# special case: complex coercion is so complex that it
# uses a macro ("__pyx_PyComplex_FromComplex()"), for
# which the argument must be simple
arg = arg.coerce_to_simple(env)
CoercionNode.__init__(self, arg)
if type is py_object_type:
# be specific about some known types
if arg.type.is_string:
......
# mode: run
# ticket: 693
cdef double complex func(double complex x):
print "hello"
return x
def test_coercion():
"""
>>> c = test_coercion()
hello
>>> c.real == 0.5
True
>>> c.imag == 1.5
True
"""
cdef object x = func(0.5 + 1.5j)
return x
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