[vala/staging: 2/2] vala: Disallow private accessors in overridable properties



commit 616f94536eddb2735360f38ff29e40e3dc277fd1
Author: Simon Werbeck <simon werbeck gmail com>
Date:   Thu Aug 14 21:47:44 2014 +0200

    vala: Disallow private accessors in overridable properties
    
    https://bugzilla.gnome.org/show_bug.cgi?id=603491

 tests/Makefile.am              |    1 +
 tests/objects/bug603491.test   |   12 ++++++++++++
 vala/valapropertyaccessor.vala |    6 ++++++
 3 files changed, 19 insertions(+), 0 deletions(-)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 359942d..c8186a8 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -174,6 +174,7 @@ TESTS = \
        objects/bug596621.vala \
        objects/bug597155.vala \
        objects/bug597161.vala \
+       objects/bug603491.test \
        objects/bug613486.vala \
        objects/bug613840.vala \
        objects/bug620675.vala \
diff --git a/tests/objects/bug603491.test b/tests/objects/bug603491.test
new file mode 100644
index 0000000..ada8952
--- /dev/null
+++ b/tests/objects/bug603491.test
@@ -0,0 +1,12 @@
+Invalid Code
+
+public abstract class Foo : Object {
+       public abstract string baz { get; private set; }
+}
+
+public class Bar : Foo {
+       public override string baz { get; private set; }
+}
+
+void main () {
+}
diff --git a/vala/valapropertyaccessor.vala b/vala/valapropertyaccessor.vala
index 9004848..81981b8 100644
--- a/vala/valapropertyaccessor.vala
+++ b/vala/valapropertyaccessor.vala
@@ -178,6 +178,12 @@ public class Vala.PropertyAccessor : Subroutine {
                        }
                }
 
+               if ((prop.is_abstract || prop.is_virtual || prop.overrides) && access == 
SymbolAccessibility.PRIVATE) {
+                       error = true;
+                       Report.error (source_reference, "Property `%s' with private accessor cannot be marked 
as abstract, virtual or override".printf (prop.get_full_name ()));
+                       return false;
+               }
+
                if (body != null) {
                        if (writable || construction) {
                                body.scope.add (value_parameter.name, value_parameter);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]