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



commit 46f38580b4f48fc26bbf5bbb047cde3c26c15a59
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                                      |  2 ++
 tests/methods/bug652098.vala                           | 10 +++++++---
 tests/objects/interface-generics.vala                  | 12 ++++++++++++
 .../class-missing-implement-interfaces-methods.test    | 18 ++++++++++++++++++
 vala/valaclass.vala                                    |  3 ++-
 5 files changed, 41 insertions(+), 4 deletions(-)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 02831dc16..24118207e 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -263,6 +263,7 @@ TESTS = \
        objects/fields.vala \
        objects/gsource.vala \
        objects/interfaces.vala \
+       objects/interface-generics.vala \
        objects/methods.vala \
        objects/paramspec.vala \
        objects/properties.vala \
@@ -537,6 +538,7 @@ 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-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/vala/valaclass.vala b/vala/valaclass.vala
index fdaabc7c5..ac2f74569 100644
--- a/vala/valaclass.vala
+++ b/vala/valaclass.vala
@@ -740,7 +740,8 @@ 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.name == m.name
+                                                                           && (impl.base_interface_type == 
null || impl.base_interface_type.data_type == iface))) {
                                                                                // 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]