]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
vala: Don't just guess and check for a matching base_interface_method too
authorRico Tzschichholz <ricotz@ubuntu.com>
Thu, 29 Nov 2018 16:59:01 +0000 (17:59 +0100)
committerRico Tzschichholz <ricotz@ubuntu.com>
Wed, 19 Dec 2018 23:51:37 +0000 (00:51 +0100)
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
tests/methods/bug652098.vala
tests/objects/interface-generics.vala [new file with mode: 0644]
tests/semantic/class-missing-implement-interfaces-methods.test [new file with mode: 0644]
tests/semantic/class-missing-implement-interfaces-methods3.test [new file with mode: 0644]
vala/valaclass.vala

index 1a18f2c13a2809aad4dc5981290d3ac73af9950b..63e62bae7b3583f08fc8b40301b0ca83c6fd69eb 100644 (file)
@@ -267,6 +267,7 @@ TESTS = \
        objects/gsource.vala \
        objects/interface_only.vala \
        objects/interfaces.vala \
+       objects/interface-generics.vala \
        objects/methods.vala \
        objects/paramspec.vala \
        objects/properties.vala \
@@ -550,6 +551,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 \
index 3cb19cab7c5ab5710a835ea333d80beeee82405b..274f001bc9ddbdd40036780bd260d719975bad5a 100644 (file)
@@ -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 (file)
index 0000000..6fd9c29
--- /dev/null
@@ -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 (file)
index 0000000..d6e12b2
--- /dev/null
@@ -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 (file)
index 0000000..11e84c6
--- /dev/null
@@ -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 () {
+}
index fdaabc7c5bedef7f8099a2d9ca9edc5d62c05a3a..2abbc776682571f991347609813bb7ee283e52ec 100644 (file)
@@ -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_no_error (m))) {
                                                                                // method is used as interface implementation, so it is not unused
                                                                                impl.version.check (source_reference);
                                                                                impl.used = true;