prevent subtyping final types in Cython (inside of the same module)
authorStefan Behnel <scoder@users.berlios.de>
Sat, 30 Oct 2010 17:35:26 +0000 (19:35 +0200)
committerStefan Behnel <scoder@users.berlios.de>
Sat, 30 Oct 2010 17:35:26 +0000 (19:35 +0200)
Cython/Compiler/Nodes.py
tests/errors/subtyping_final_class.pyx [new file with mode: 0644]

index a7c9592683a0a5329f51a20557d94ca5c0b32ebe..e109b5071ba5a7b04038d4cd1c3dc27fa2a40bf4 100644 (file)
@@ -3104,7 +3104,12 @@ class CClassDefNode(ClassDefNode):
                     elif not base_class_entry.type.is_extension_type:
                         error(self.pos, "'%s' is not an extension type" % self.base_class_name)
                     elif not base_class_entry.type.is_complete():
-                        error(self.pos, "Base class '%s' is incomplete" % self.base_class_name)
+                        error(self.pos, "Base class '%s' of type '%s' is incomplete" % (
+                            self.base_class_name, self.class_name))
+                    elif base_class_entry.type.scope and base_class_entry.type.scope.directives and \
+                             base_class_entry.type.scope.directives.get('final', False):
+                        error(self.pos, "Base class '%s' of type '%s' is final" % (
+                            self.base_class_name, self.class_name))
                     else:
                         self.base_type = base_class_entry.type
         has_body = self.body is not None
diff --git a/tests/errors/subtyping_final_class.pyx b/tests/errors/subtyping_final_class.pyx
new file mode 100644 (file)
index 0000000..477669b
--- /dev/null
@@ -0,0 +1,13 @@
+
+cimport cython
+
+@cython.final
+cdef class FinalClass:
+    pass
+
+cdef class SubType(FinalClass):
+    pass
+
+_ERRORS = """
+8:5: Base class 'FinalClass' of type 'SubType' is final
+"""