[vala/0.40] codegen: Don't set implemenation of interface property to its own



commit c1c526d3c0cff05d63d9382fe22a960b7c0ca445
Author: Rico Tzschichholz <ricotz ubuntu com>
Date:   Tue Jan 7 17:20:25 2020 +0100

    codegen: Don't set implemenation of interface property to its own
    
    A base-class is allowed to provide interface implementations for methods
    and properties. If those exist without an explicit implementation in the
    sub-class we then we end up finding the interface property itself. Using
    that is obviously wrong and causes a cyclic call stack.
    
    Fixes https://gitlab.gnome.org/GNOME/vala/issues/891

 codegen/valagtypemodule.vala                    |  5 +++++
 tests/Makefile.am                               |  1 +
 tests/objects/interface-property-base-impl.vala | 16 ++++++++++++++++
 3 files changed, 22 insertions(+)
---
diff --git a/codegen/valagtypemodule.vala b/codegen/valagtypemodule.vala
index 9c9635be0..cb4efa213 100644
--- a/codegen/valagtypemodule.vala
+++ b/codegen/valagtypemodule.vala
@@ -1526,6 +1526,11 @@ public class Vala.GTypeModule : GErrorModule {
                                        base_property = cl_prop.base_interface_property;
                                }
 
+                               // Our base class provides this interface implementation
+                               if (prop == base_property) {
+                                       continue;
+                               }
+
                                var ciface = new CCodeIdentifier ("iface");
 
                                if (base_property.get_accessor != null && prop.get_accessor != null) {
diff --git a/tests/Makefile.am b/tests/Makefile.am
index a7318613c..2fb048652 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -298,6 +298,7 @@ TESTS = \
        objects/interface-base-access.vala \
        objects/interfaces.vala \
        objects/interface-property-base-access.vala \
+       objects/interface-property-base-impl.vala \
        objects/interface-property-delegate.vala \
        objects/interface-property-override.vala \
        objects/methods.vala \
diff --git a/tests/objects/interface-property-base-impl.vala b/tests/objects/interface-property-base-impl.vala
new file mode 100644
index 000000000..21988c39c
--- /dev/null
+++ b/tests/objects/interface-property-base-impl.vala
@@ -0,0 +1,16 @@
+public interface IFoo : Object {
+    public abstract int prop { get; set; }
+}
+
+public class Foo : Object, IFoo {
+    public int prop { get; set; }
+}
+
+public class Bar : Foo, IFoo {
+}
+
+void main (){
+    IFoo bar = new Bar ();
+    bar.prop = 42;
+    assert (bar.prop == 42);
+}


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