[vala/wip/issue548: 2/2] WIP vala: Allow explicit interface methods to be virtual
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/wip/issue548: 2/2] WIP vala: Allow explicit interface methods to be virtual
- Date: Sat, 1 Dec 2018 14:47:59 +0000 (UTC)
commit c4729b026be57e39f88dfdbfe0db638a9b6b1a35
Author: Rico Tzschichholz <ricotz ubuntu com>
Date: Sat Dec 1 15:27:08 2018 +0100
WIP vala: Allow explicit interface methods to be virtual
tests/Makefile.am | 1 +
tests/objects/classes-interfaces-virtuals.vala | 34 ++++++++++++++++++++++++++
vala/valaclass.vala | 12 ++++++++-
3 files changed, 46 insertions(+), 1 deletion(-)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 15cefa931..442431592 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -253,6 +253,7 @@ TESTS = \
objects/chainup.vala \
objects/classes.vala \
objects/classes-interfaces.vala \
+ objects/classes-interfaces-virtuals.vala \
objects/compact-class.vala \
objects/compact-class-destructor.vala \
objects/constructor-variadic.test \
diff --git a/tests/objects/classes-interfaces-virtuals.vala b/tests/objects/classes-interfaces-virtuals.vala
new file mode 100644
index 000000000..cf56c62b7
--- /dev/null
+++ b/tests/objects/classes-interfaces-virtuals.vala
@@ -0,0 +1,34 @@
+interface IFoo : Object {
+ public abstract int foo ();
+}
+
+interface IBar : Object {
+ public abstract string foo ();
+}
+
+class Foo : Object, IFoo, IBar {
+ public virtual int IFoo.foo () {
+ return 42;
+ }
+ public string IBar.foo () {
+ return "foo";
+ }
+}
+
+class Bar : Foo {
+ public override int foo () {
+ return 23;
+ }
+}
+
+void main () {
+ var foo = new Foo ();
+ assert (foo.foo () == 42);
+ assert (((IBar) foo).foo () == "foo");
+
+ var bar = new Bar ();
+ assert (bar.foo () == 23);
+ assert (((Foo) bar).foo () == 23);
+ assert (((IFoo) bar).foo () == 23);
+ assert (((IBar) bar).foo () == "foo");
+}
diff --git a/vala/valaclass.vala b/vala/valaclass.vala
index 2be6b2e75..aa206cd34 100644
--- a/vala/valaclass.vala
+++ b/vala/valaclass.vala
@@ -297,11 +297,21 @@ public class Vala.Class : ObjectTypeSymbol {
}
}
+ Symbol? sym = null;
+ if (m.base_interface_type != null && !(m.is_abstract || m.is_virtual)) {
+ sym = scope.lookup (m.name);
+ if (sym != null) {
+ scope.remove (m.name);
+ }
+ }
base.add_method (m);
// explicit interface method implementation
- if (m.base_interface_type != null) {
+ if (m.base_interface_type != null && !(m.is_abstract || m.is_virtual)) {
scope.remove (m.name);
scope.add (null, m);
+ if (sym != null) {
+ scope.add (m.name, sym);
+ }
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]