Commit e224cced authored by Stefan Behnel's avatar Stefan Behnel

allow coercion of temp values to C++ classes

parent dd71d21c
......@@ -7297,8 +7297,9 @@ class TypecastNode(ExprNode):
self.operand.analyse_types(env)
to_py = self.type.is_pyobject
from_py = self.operand.type.is_pyobject
if from_py and not to_py and self.operand.is_ephemeral() and not self.type.is_numeric:
error(self.pos, "Casting temporary Python object to non-numeric non-Python type")
if from_py and not to_py and self.operand.is_ephemeral():
if not self.type.is_numeric and not self.type.is_cpp_class:
error(self.pos, "Casting temporary Python object to non-numeric non-Python type")
if to_py and not from_py:
if self.type is bytes_type and self.operand.type.is_int:
# FIXME: the type cast node isn't needed in this case
......
......@@ -39,6 +39,16 @@ def test_encode_to_string(o):
cdef string s = o.encode('ascii')
return s
def test_encode_to_string_cast(o):
"""
>>> normalize(test_encode_to_string_cast('abc'))
'abc'
>>> normalize(test_encode_to_string_cast('abc\\x00def'))
'abc\\x00def'
"""
s = <string>o.encode('ascii')
return s
def test_bytes_encode_to_string(bytes o):
"""
>>> normalize(test_bytes_encode_to_string('abc'))
......
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