fix crash when calling non-trivial type constructors
authorStefan Behnel <scoder@users.berlios.de>
Fri, 11 Dec 2009 14:46:18 +0000 (15:46 +0100)
committerStefan Behnel <scoder@users.berlios.de>
Fri, 11 Dec 2009 14:46:18 +0000 (15:46 +0100)
Cython/Compiler/ExprNodes.py
tests/run/clone_type.pyx [new file with mode: 0644]

index 57572fdb0e11b3884607097b74f856829b2e7c13..d2789833eef8cd1f593f5f288f6b6dfcc4845ed1 100644 (file)
@@ -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 (file)
index 0000000..dd5cc7b
--- /dev/null
@@ -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 = <MyType>type(self)()
+        return clone