]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
vala: Report error for public creation methods of abstract classes
authorRico Tzschichholz <ricotz@ubuntu.com>
Tue, 12 Mar 2019 09:29:46 +0000 (10:29 +0100)
committerRico Tzschichholz <ricotz@ubuntu.com>
Sun, 17 Mar 2019 18:40:19 +0000 (19:40 +0100)
Only report a warning for external creation methods to reduce the initial
fallout.

Fixes https://gitlab.gnome.org/GNOME/vala/issues/766

tests/Makefile.am
tests/objects/constructor-abstract-public.test [new file with mode: 0644]
vala/valaclass.vala

index 6c1653bda67f5c0bb153a81fe3dd2f2606e65f8e..41481e7e85f2b738de7b8986d40873260beb3bfa 100644 (file)
@@ -279,6 +279,7 @@ TESTS = \
        objects/classes-implicit-implementation.vala \
        objects/compact-class.vala \
        objects/compact-class-destructor.vala \
+       objects/constructor-abstract-public.test \
        objects/constructor-variadic.test \
        objects/constructors.vala \
        objects/destructors.vala \
diff --git a/tests/objects/constructor-abstract-public.test b/tests/objects/constructor-abstract-public.test
new file mode 100644 (file)
index 0000000..4058ccf
--- /dev/null
@@ -0,0 +1,9 @@
+Invalid Code
+
+abstract class Foo {
+       public Foo () {
+       }
+}
+
+void main () {
+}
index 51e8fbade672c685e592020da05bd07e53dc54eb..933a67c26d6ea37600d24d0cb141a1bcadbb31ed 100644 (file)
@@ -296,6 +296,16 @@ public class Vala.Class : ObjectTypeSymbol {
                                m.error = true;
                                return;
                        }
+                       if (is_abstract && cm.access == SymbolAccessibility.PUBLIC) {
+                               //TODO Report an error for external constructors too
+                               if (external_package) {
+                                       Report.warning (m.source_reference, "Creation method of abstract class cannot be public.");
+                               } else {
+                                       Report.error (m.source_reference, "Creation method of abstract class cannot be public.");
+                                       error = true;
+                                       return;
+                               }
+                       }
                }
 
                base.add_method (m);