[vala/staging] vala: Explicit "new" method may be incompatible with a posssible base method



commit 00bef7c5ef7d6915b86fe5d2db0118a546a5e9c1
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 de2a0e032..78c939a2f 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -355,6 +355,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]