[vala/0.48] 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.48] vala: Explicit "new" method may be incompatible with a posssible base method
- Date: Mon, 18 May 2020 12:38:47 +0000 (UTC)
commit bfc7f96a9e3367d292c9ff9033178c1fb8ba0896
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 bcdc465e1..142bacea2 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -354,6 +354,7 @@ TESTS = \
objects/class_only.vala \
objects/class-destroysinstance.vala \
objects/class-inner-types.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 e617f9d61..ef8a48dae 100644
--- a/vala/valamethod.vala
+++ b/vala/valamethod.vala
@@ -687,7 +687,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]