From ff35cf52cc5404eb0023b4880e89f281a5e7d4c0 Mon Sep 17 00:00:00 2001 From: Stefan Behnel Date: Fri, 11 Dec 2009 15:46:18 +0100 Subject: [PATCH] fix crash when calling non-trivial type constructors --- Cython/Compiler/ExprNodes.py | 4 +++- tests/run/clone_type.pyx | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 tests/run/clone_type.pyx diff --git a/Cython/Compiler/ExprNodes.py b/Cython/Compiler/ExprNodes.py index 57572fdb..d2789833 100644 --- a/Cython/Compiler/ExprNodes.py +++ b/Cython/Compiler/ExprNodes.py @@ -2471,7 +2471,9 @@ class SimpleCallNode(CallNode): self.arg_tuple = TupleNode(self.pos, args = self.args) self.arg_tuple.analyse_types(env) self.args = None - if func_type is Builtin.type_type and function.entry.is_builtin and \ + if func_type is Builtin.type_type and function.is_name and \ + function.entry and \ + function.entry.is_builtin and \ function.entry.name in Builtin.types_that_construct_their_instance: # calling a builtin type that returns a specific object type if function.entry.name == 'float': diff --git a/tests/run/clone_type.pyx b/tests/run/clone_type.pyx new file mode 100644 index 00000000..dd5cc7b8 --- /dev/null +++ b/tests/run/clone_type.pyx @@ -0,0 +1,14 @@ +cdef class MyType: + def dup(self): + """ + >>> x1 = MyType() + >>> isinstance(x1, MyType) + True + >>> x2 = x1.dup() + >>> isinstance(x2, MyType) + True + >>> x1 != x2 + True + """ + cdef MyType clone = type(self)() + return clone -- 2.26.2