From: Robert Bradshaw Date: Thu, 4 Feb 2010 21:58:00 +0000 (-0800) Subject: Fix assignable_from for cpp classes. X-Git-Tag: 0.13.beta0~353^2~2 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=615af2d193b250f90b446da21c02a09f66488bcf;p=cython.git Fix assignable_from for cpp classes. --- diff --git a/Cython/Compiler/PyrexTypes.py b/Cython/Compiler/PyrexTypes.py index 4f068ace..5b78c8f1 100755 --- a/Cython/Compiler/PyrexTypes.py +++ b/Cython/Compiler/PyrexTypes.py @@ -1891,6 +1891,10 @@ class CppClassType(CType): return 1 return 0 + def assignable_from_resolved_type(self, other_type): + # TODO: handle operator=(...) here? + return other_type.is_cpp_class and other_type.is_subclass(self) + def attributes_known(self): return self.scope is not None diff --git a/tests/run/cpp_classes.pyx b/tests/run/cpp_classes.pyx index 5e5747df..9c51aed9 100644 --- a/tests/run/cpp_classes.pyx +++ b/tests/run/cpp_classes.pyx @@ -48,3 +48,17 @@ def test_square_area(w): finally: del sqr +cdef double get_area(Rectangle s): + return s.area() + +def test_value_call(int w): + """ + >>> test_value_call(5) + (25.0, 25.0) + """ + cdef Square *sqr = new Square(w) + cdef Rectangle *rect = sqr + try: + return get_area(sqr[0]), get_area(rect[0]) + finally: + del sqr