[vala/wip/issue548: 3/4] vala: Don't just guess and check for a matching base_interface_method too



commit f9006a1a503b62dccfbb28a81e799d8a24d9adec
Author: Rico Tzschichholz <ricotz ubuntu com>
Date:   Thu Nov 29 17:59:01 2018 +0100

    vala: Don't just guess and check for a matching base_interface_method too
    
    This fixes class with multiple interfaces which require implementations of
    methods with conflicting naming while the explicit interface-type reference
    is not present yet.
    
    Extend the present test-case for runtime checking. This will still silently
    connect matching base-class methods as before as introduced in
    e1a3ff9470763e7c6ff5a887036390bd418f4e46
    
    Fixes https://gitlab.gnome.org/GNOME/vala/issues/548

 tests/Makefile.am                                  |  3 +++
 tests/methods/bug652098.vala                       | 10 +++++++---
 tests/objects/interface-generics.vala              | 12 +++++++++++
 ...class-missing-implement-interfaces-methods.test | 18 +++++++++++++++++
 ...lass-missing-implement-interfaces-methods3.test | 23 ++++++++++++++++++++++
 vala/valaclass.vala                                |  5 ++++-
 6 files changed, 67 insertions(+), 4 deletions(-)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index a785038b4..9fe2ea6bd 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -264,6 +264,7 @@ TESTS = \
        objects/fields.vala \
        objects/gsource.vala \
        objects/interfaces.vala \
+       objects/interface-generics.vala \
        objects/methods.vala \
        objects/paramspec.vala \
        objects/properties.vala \
@@ -538,6 +539,8 @@ TESTS = \
        semantic/class-compact-property-baseaccess.test \
        semantic/class-missing-implement-interface-method.test \
        semantic/class-missing-implement-interface-property.test \
+       semantic/class-missing-implement-interfaces-methods.test \
+       semantic/class-missing-implement-interfaces-methods3.test \
        semantic/class-missing-implement-method.test \
        semantic/class-missing-implement-property.test \
        semantic/class-missing-prerequisites.test \
diff --git a/tests/methods/bug652098.vala b/tests/methods/bug652098.vala
index 3cb19cab7..274f001bc 100644
--- a/tests/methods/bug652098.vala
+++ b/tests/methods/bug652098.vala
@@ -27,12 +27,13 @@ class Obj2 : Object, Iface1, Iface2 {
 }
 
 class Base : Object {
-       public void foo () {
+       public int foo () {
+               return 42;
        }
 }
 
 interface Iface : Object {
-       public abstract void foo ();
+       public abstract int foo ();
 }
 
 class Concrete : Base, Iface {
@@ -52,4 +53,7 @@ void main () {
 
        assert (iface1.foo () == 1);
        assert (iface2.foo () == 2);
-}
\ No newline at end of file
+
+       var concrete = new Concrete ();
+       assert (((Iface) concrete).foo () == 42);
+}
diff --git a/tests/objects/interface-generics.vala b/tests/objects/interface-generics.vala
new file mode 100644
index 000000000..6fd9c29f8
--- /dev/null
+++ b/tests/objects/interface-generics.vala
@@ -0,0 +1,12 @@
+interface IFoo<G> : Object {
+       public abstract G get ();
+}
+
+class Foo<G> : Object, IFoo<G> {
+       public new G get () {
+               return null;
+       }
+}
+
+void main() {
+}
diff --git a/tests/semantic/class-missing-implement-interfaces-methods.test 
b/tests/semantic/class-missing-implement-interfaces-methods.test
new file mode 100644
index 000000000..d6e12b21f
--- /dev/null
+++ b/tests/semantic/class-missing-implement-interfaces-methods.test
@@ -0,0 +1,18 @@
+Invalid Code
+
+interface IFoo : Object {
+       public abstract string foo ();
+}
+
+interface IBar : Object {
+       public abstract int foo ();
+}
+
+class Manam : Object, IFoo, IBar {
+       public string foo () {
+               return "foo";
+       }
+}
+
+void main() {
+}
diff --git a/tests/semantic/class-missing-implement-interfaces-methods3.test 
b/tests/semantic/class-missing-implement-interfaces-methods3.test
new file mode 100644
index 000000000..11e84c6da
--- /dev/null
+++ b/tests/semantic/class-missing-implement-interfaces-methods3.test
@@ -0,0 +1,23 @@
+Invalid Code
+
+class Base : Object {
+       public void foo () {
+       }
+}
+
+interface IFoo : Base {
+       public abstract string foo ();
+}
+
+interface IBar : Base {
+       public abstract int foo ();
+}
+
+class Manam : Base, IFoo, IBar {
+       public int IBar.foo () {
+               return 23;
+       }
+}
+
+void main () {
+}
diff --git a/vala/valaclass.vala b/vala/valaclass.vala
index fdaabc7c5..2be6b2e75 100644
--- a/vala/valaclass.vala
+++ b/vala/valaclass.vala
@@ -740,7 +740,10 @@ public class Vala.Class : ObjectTypeSymbol {
                                                        var base_class = this;
                                                        while (base_class != null) {
                                                                foreach (var impl in base_class.get_methods 
()) {
-                                                                       if (impl.name == m.name && 
(impl.base_interface_type == null || impl.base_interface_type.data_type == iface)) {
+                                                                       if (impl.base_interface_method == m 
|| (base_class != this
+                                                                           && impl.base_interface_method == 
null && impl.name == m.name
+                                                                           && (impl.base_interface_type == 
null || impl.base_interface_type.data_type == iface)
+                                                                           && impl.compatible (m, null))) {
                                                                                // method is used as 
interface implementation, so it is not unused
                                                                                impl.version.check 
(source_reference);
                                                                                impl.used = true;


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