Commit 395b89c1 authored by da-woods's avatar da-woods Committed by GitHub

Fix conversion from DictNode to std::map (GH-4231)

Reported in https://github.com/cython/cython/pull/4228
parent 28c98012
......@@ -8871,8 +8871,7 @@ class DictNode(ExprNode):
value = value.arg
item.value = value.coerce_to(member.type, env)
else:
self.type = error_type
error(self.pos, "Cannot interpret dict as type '%s'" % dst_type)
return super(DictNode, self).coerce_to(dst_type, env)
return self
def release_errors(self):
......
......@@ -10,6 +10,7 @@ for i in reversed(range(j, [], 2)):
pass
for i in reversed(range(j, [], -2)):
pass
# code below is no longer a compile-time error (although won't run without an exception)
for i in reversed(range({}, j, 2)):
pass
for i in reversed(range({}, j, -2)):
......@@ -24,8 +25,4 @@ _ERRORS = """
7:24: Cannot coerce list to type 'long'
9:27: Cannot coerce list to type 'long'
11:27: Cannot coerce list to type 'long'
13:24: Cannot interpret dict as type 'long'
15:24: Cannot interpret dict as type 'long'
17:27: Cannot interpret dict as type 'long'
19:27: Cannot interpret dict as type 'long'
"""
......@@ -97,6 +97,23 @@ def test_int_vector(o):
cdef vector[int] v = o
return v
cdef vector[int] takes_vector(vector[int] x):
return x
def test_list_literal_to_vector():
"""
>>> test_list_literal_to_vector()
[1, 2, 3]
"""
return takes_vector([1, 2, 3])
def test_tuple_literal_to_vector():
"""
>>> test_tuple_literal_to_vector()
[1, 2, 3]
"""
return takes_vector((1, 2, 3))
def test_string_vector(s):
"""
>>> list(map(normalize, test_string_vector('ab cd ef gh'.encode('ascii'))))
......@@ -241,3 +258,14 @@ def test_enum_map(o):
"""
cdef map[Color, Color] m = o
return m
cdef map[unsigned int, unsigned int] takes_map(map[unsigned int, unsigned int] m):
return m
def test_dict_literal_to_map():
"""
>>> test_dict_literal_to_map()
{1: 1}
"""
return takes_map({1: 1}) # https://github.com/cython/cython/pull/4228
# DictNode could not be converted directly
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