[vala/0.40] vala: Allow to override base interface properties explicitly



commit fbac5e627908cbb242b0e712a02dc8336c12ffc3
Author: Jeremy Philippe <jeremy philippe gmail com>
Date:   Sat Dec 21 11:54:30 2019 +0100

    vala: Allow to override base interface properties explicitly

 tests/Makefile.am                              |  1 +
 tests/objects/interface-property-override.vala | 54 ++++++++++++++++++++++++++
 vala/valaproperty.vala                         |  2 +-
 3 files changed, 56 insertions(+), 1 deletion(-)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index aff3d63d9..a7318613c 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -299,6 +299,7 @@ TESTS = \
        objects/interfaces.vala \
        objects/interface-property-base-access.vala \
        objects/interface-property-delegate.vala \
+       objects/interface-property-override.vala \
        objects/methods.vala \
        objects/paramspec.vala \
        objects/properties.vala \
diff --git a/tests/objects/interface-property-override.vala b/tests/objects/interface-property-override.vala
new file mode 100644
index 000000000..e9d9b0cda
--- /dev/null
+++ b/tests/objects/interface-property-override.vala
@@ -0,0 +1,54 @@
+interface IFoo {
+       public virtual int bar {
+               get {
+                       assert_not_reached ();
+               }
+               set {
+                       assert_not_reached ();
+               }
+       }
+}
+
+class Foo : IFoo {
+       public override int bar {
+               get {
+                       return 42;
+               }
+               set {
+               }
+       }
+}
+
+interface IBar : Object {
+       public virtual int foo {
+               get {
+                       assert_not_reached ();
+               }
+               set {
+                       assert_not_reached ();
+               }
+       }
+}
+
+class Bar : Object, IBar {
+       public override int foo {
+               get {
+                       return 23;
+               }
+               set {
+               }
+       }
+}
+
+void main () {
+       {
+               var foo = new Foo ();
+               foo.bar = 0;
+               assert (foo.bar == 42);
+       }
+       {
+               var bar = new Bar ();
+               bar.foo = 0;
+               assert (bar.foo == 23);
+       }
+}
diff --git a/vala/valaproperty.vala b/vala/valaproperty.vala
index e0a8e4390..4efb9aba0 100644
--- a/vala/valaproperty.vala
+++ b/vala/valaproperty.vala
@@ -463,7 +463,7 @@ public class Vala.Property : Symbol, Lockable {
                        Report.error (source_reference, "property type `%s` is less accessible than property 
`%s`".printf (property_type.to_string (), get_full_name ()));
                }
 
-               if (overrides && base_property == null) {
+               if (overrides && base_property == null && base_interface_property == null) {
                        Report.error (source_reference, "%s: no suitable property found to override".printf 
(get_full_name ()));
                }
 


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