]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
vala: Don't allow inheritance of compact class from non-compact class
authorRico Tzschichholz <ricotz@ubuntu.com>
Mon, 22 Apr 2024 17:53:14 +0000 (19:53 +0200)
committerRico Tzschichholz <ricotz@ubuntu.com>
Wed, 29 May 2024 08:35:35 +0000 (10:35 +0200)
tests/Makefile.am
tests/semantic/class-compact-inheritance.test [new file with mode: 0644]
vala/valaclass.vala

index 5bde146b3a4a706734eaf7830663d24a34c09db9..6186afc50895f9cd0fe91e2c9ee1dcba5ecce4ce 100644 (file)
@@ -1104,6 +1104,7 @@ TESTS = \
        semantic/class-compact-field-lock.test \
        semantic/class-compact-field-private.test \
        semantic/class-compact-derived-instance-field.test \
+       semantic/class-compact-inheritance.test \
        semantic/class-compact-interface.test \
        semantic/class-compact-method-baseaccess.test \
        semantic/class-compact-property-baseaccess.test \
diff --git a/tests/semantic/class-compact-inheritance.test b/tests/semantic/class-compact-inheritance.test
new file mode 100644 (file)
index 0000000..3daed3c
--- /dev/null
@@ -0,0 +1,11 @@
+Invalid Code
+
+class Foo {
+}
+
+[Compact]
+class Bar : Foo {
+}
+
+void main () {
+}
index cf2943e4de15a4bd6455b8580f003833671c769c..c71e540c8620f1e8a21dbef501b9cc7fd4f3e34b 100644 (file)
@@ -610,6 +610,12 @@ public class Vala.Class : ObjectTypeSymbol {
                        }
                }
 
+               if (base_class != null && !base_class.is_compact && has_attribute ("Compact")) {
+                       error = true;
+                       Report.error (source_reference, "Compact class `%s' cannot inherit from non-compact class `%s'", get_full_name (), base_class.get_full_name ());
+                       return false;
+               }
+
                /* process enums first to avoid order problems in C code */
                foreach (Enum en in get_enums ()) {
                        en.check (context);