Commit fd728734 authored by Kirill Smelkov's avatar Kirill Smelkov

X allow coercion only from the same component types

parent 482e38c4
......@@ -4063,10 +4063,16 @@ class CTupleType(CType):
return True
def assignable_from_resolved_type(self, src_type):
if src_type.is_cpp_class and src_type.cname == "std::pair" and len(src_type.templates) == 2:
# XXX len self.xxx == len src_type.templates
# XXX types are assignable
# (X,Y) can be assigned from std::pair[X,Y]
if src_type.is_cpp_class and src_type.cname == "std::pair":
if not (len(self.components) == len(src_type.templates) == 2):
return False
for (c_dst, c_src) in zip(self.components, src_type.templates):
if not c_dst.same_as(c_src):
return False
return True
"""
print
#from Cython.Compiler.Pipeline import dumptree
#dumptree(src_type)
......@@ -4075,7 +4081,8 @@ class CTupleType(CType):
print src_type.cname
print src_type.templates
print
return 1 # XXX check types match
return 1 # XXX check types are the same
"""
return super(CTupleType, self).assignable_from_resolved_type(src_type)
......
# tag: cpp
# mode: error
from libcpp.utility cimport pair
cdef void f(pair[int,double] pxy) nogil:
cdef int x = pxy
cdef (int, double, int) xyz = pxy
# NOTE the following is also error, simplary to how (int, int) cannot be assigned from (int, double)
cdef (int, int) ixy = pxy
_ERRORS = u"""
7:17: Cannot assign type 'pair[int,double]' to 'int'
8:34: Cannot assign type 'pair[int,double]' to '(int, double, int)'
11:26: Cannot assign type 'pair[int,double]' to '(int, int)'
"""
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