From 615af2d193b250f90b446da21c02a09f66488bcf Mon Sep 17 00:00:00 2001 From: Robert Bradshaw Date: Thu, 4 Feb 2010 13:58:00 -0800 Subject: [PATCH] Fix assignable_from for cpp classes. --- Cython/Compiler/PyrexTypes.py | 4 ++++ tests/run/cpp_classes.pyx | 14 ++++++++++++++ 2 files changed, 18 insertions(+) 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 -- 2.26.2