]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
vala: Explicit "new" method may be incompatible with a posssible base method
authorRico Tzschichholz <ricotz@ubuntu.com>
Mon, 18 May 2020 10:26:14 +0000 (12:26 +0200)
committerRico Tzschichholz <ricotz@ubuntu.com>
Mon, 18 May 2020 11:21:58 +0000 (13:21 +0200)
tests/Makefile.am
tests/objects/class-new-no-override.vala [new file with mode: 0644]
vala/valamethod.vala

index de2a0e032c0570a314c775ea3821f1f9b2d87cbc..78c939a2feeec3bb9a6c4dda0aa95842e4b8c3db 100644 (file)
@@ -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 (file)
index 0000000..2ab2114
--- /dev/null
@@ -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);
+}
index e617f9d615c7a56bfe57d528762537791a1b70a9..ef8a48dae8dd8713445782d5e810b866c448eeb2 100644 (file)
@@ -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));