Commit f925d315 authored by Stefan Behnel's avatar Stefan Behnel

properly coerce Py_UCS4 characters to a unicode string when for-loop target requires it

parent afe1395f
......@@ -348,15 +348,19 @@ class IterationTransform(Visitor.VisitorTransform):
is_temp = False,
))
target_assign = Nodes.SingleAssignmentNode(
pos = node.target.pos,
lhs = node.target,
rhs = ExprNodes.PythonCapiCallNode(
target_value = ExprNodes.PythonCapiCallNode(
slice_node.pos, "__Pyx_PyUnicode_READ",
self.PyUnicode_READ_func_type,
args = [kind_temp, data_temp, counter_temp],
is_temp = False,
))
)
if target_value.type != node.target.type:
target_value = target_value.coerce_to(node.target.type,
self.current_scope)
target_assign = Nodes.SingleAssignmentNode(
pos = node.target.pos,
lhs = node.target,
rhs = target_value)
body = Nodes.StatListNode(
node.pos,
stats = [target_assign, node.body])
......
......@@ -81,6 +81,16 @@ def str_type_is_unicode():
cdef str s = 'abc'
return str, s
def loop_over_unicode_literal():
"""
>>> print( loop_over_unicode_literal() )
Py_UCS4
"""
# Py_UCS4 can represent any Unicode character
for uchar in 'abcdefg':
pass
return cython.typeof(uchar)
def list_comp():
"""
>>> list_comp()
......
......@@ -201,6 +201,17 @@ def count_lower_case_characters_slice_reversed(unicode ustring):
count += 1
return count
def loop_object_over_unicode_literal():
"""
>>> print(loop_object_over_unicode_literal())
abcdefg
"""
cdef object uchar
chars = []
for uchar in u'abcdefg':
chars.append(uchar)
return u''.join(chars)
@cython.test_assert_path_exists('//SwitchStatNode')
@cython.test_fail_if_path_exists('//ForInStatNode')
def iter_and_in():
......
......@@ -341,6 +341,16 @@ def loop_over_unicode():
pass
return typeof(uchar)
def loop_over_unicode_literal():
"""
>>> print( loop_over_unicode_literal() )
Py_UCS4
"""
# Py_UCS4 can represent any Unicode character
for uchar in u'abcdefg':
pass
return typeof(uchar)
def loop_over_int_array():
"""
>>> print( loop_over_int_array() )
......
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