summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRico Tzschichholz <ricotz@ubuntu.com>2018-11-29 17:59:01 +0100
committerRico Tzschichholz <ricotz@ubuntu.com>2018-12-20 00:51:37 +0100
commit8bc6cc74406df77e134850c91f50a71ff037180a (patch)
treea229b201d97a6869521f061676e3899ac268665f
parent3399a1c572121c87a518c010422a2fad9ce30589 (diff)
downloadvala-8bc6cc74406df77e134850c91f50a71ff037180a.tar.gz
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
-rw-r--r--tests/Makefile.am3
-rw-r--r--tests/methods/bug652098.vala10
-rw-r--r--tests/objects/interface-generics.vala12
-rw-r--r--tests/semantic/class-missing-implement-interfaces-methods.test18
-rw-r--r--tests/semantic/class-missing-implement-interfaces-methods3.test23
-rw-r--r--vala/valaclass.vala5
6 files changed, 67 insertions, 4 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 1a18f2c13..63e62bae7 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -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 \
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..2abbc7766 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_no_error (m))) {
// method is used as interface implementation, so it is not unused
impl.version.check (source_reference);
impl.used = true;