[vala/0.46] vala: Explicit "new" method may be incompatible with a posssible base method
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/0.46] vala: Explicit "new" method may be incompatible with a posssible base method
- Date: Tue, 19 May 2020 16:29:51 +0000 (UTC)
commit 93731daf1f6be12c036a6357dd096c43ac3dadc0
Author: Rico Tzschichholz <ricotz ubuntu com>
Date: Mon May 18 12:26:14 2020 +0200
vala: Explicit "new" method may be incompatible with a posssible base method
tests/Makefile.am | 1 +
tests/objects/class-new-no-override.vala | 17 +++++++++++++++++
vala/valamethod.vala | 2 +-
3 files changed, 19 insertions(+), 1 deletion(-)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 8fe220f69..3e63794f7 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -339,6 +339,7 @@ TESTS = \
objects/chainup.vala \
objects/class_only.vala \
objects/class-destroysinstance.vala \
+ objects/class-new-no-override.vala \
objects/classes.vala \
objects/classes-interfaces.vala \
objects/classes-interfaces-virtuals.vala \
diff --git a/tests/objects/class-new-no-override.vala b/tests/objects/class-new-no-override.vala
new file mode 100644
index 000000000..2ab2114aa
--- /dev/null
+++ b/tests/objects/class-new-no-override.vala
@@ -0,0 +1,17 @@
+interface IFoo : Object {
+ public virtual void foo (int i) {
+ assert (i == 42);
+ }
+}
+
+class Bar : Object, IFoo {
+ public new string foo () {
+ return "bar";
+ }
+}
+
+void main () {
+ var bar = new Bar ();
+ assert (bar.foo () == "bar");
+ ((IFoo) bar).foo (42);
+}
diff --git a/vala/valamethod.vala b/vala/valamethod.vala
index 40bb578a6..1084746cb 100644
--- a/vala/valamethod.vala
+++ b/vala/valamethod.vala
@@ -685,7 +685,7 @@ public class Vala.Method : Subroutine, Callable {
_base_interface_method = base_match;
copy_attribute_double (base_match, "CCode", "instance_pos");
return;
- } else if (invalid_base_match != null) {
+ } else if (!hides && invalid_base_match != null) {
error = true;
var base_method_type = new MethodType (invalid_base_match);
Report.error (source_reference, "overriding method `%s' is incompatible with base
method `%s': %s.".printf (get_full_name (), base_method_type.to_prototype_string (), invalid_error));
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]