[vala/0.48] vala: Warn about usage of override to implement abstract interface methods



commit 0b298accde718c4d3a6a6a28080aa4562aa5be06
Author: Rico Tzschichholz <ricotz ubuntu com>
Date:   Sun Apr 5 14:45:34 2020 +0200

    vala: Warn about usage of override to implement abstract interface methods
    
    Fixes criticals in GAsyncModule.visit_method()
    
        vala_symbol_get_parent_symbol: assertion 'self != NULL' failed
    
    which were introduced with 12db9b7eeb1f53975010d89839d554b5fcf99831

 tests/Makefile.am                                  |  1 +
 .../objects/interface-abstract-async-override.vala | 23 ++++++++++++++++++++++
 vala/valamethod.vala                               |  3 +++
 3 files changed, 27 insertions(+)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index f87bcf2ba..cca6a2927 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -376,6 +376,7 @@ TESTS = \
        objects/interface-base-access.vala \
        objects/interface-inner-types.vala \
        objects/interfaces.vala \
+       objects/interface-abstract-async-override.vala \
        objects/interface-generics.vala \
        objects/interface-property-base-access.vala \
        objects/interface-property-base-impl.vala \
diff --git a/tests/objects/interface-abstract-async-override.vala 
b/tests/objects/interface-abstract-async-override.vala
new file mode 100644
index 000000000..2af7f4b86
--- /dev/null
+++ b/tests/objects/interface-abstract-async-override.vala
@@ -0,0 +1,23 @@
+interface IFoo : Object {
+       public abstract async int foo ();
+}
+
+class Bar : Object, IFoo {
+       public override async int foo () {
+               return 42;
+       }
+}
+
+MainLoop loop;
+
+void main () {
+       loop = new MainLoop ();
+
+       IFoo bar = new Bar ();
+       bar.foo.begin ((o,r) => {
+               assert (((IFoo) o).foo.end (r) == 42);
+               loop.quit ();
+       });
+       loop.run ();
+}
+
diff --git a/vala/valamethod.vala b/vala/valamethod.vala
index 817888309..35e0cc810 100644
--- a/vala/valamethod.vala
+++ b/vala/valamethod.vala
@@ -929,6 +929,9 @@ public class Vala.Method : Subroutine, Callable {
                                Report.error (source_reference, "A struct member `%s' cannot be marked as 
override, virtual, or abstract".printf (get_full_name ()));
                                return false;
                        }
+               } else if (overrides && base_method == null && base_interface_method != null && 
base_interface_method.is_abstract) {
+                       Report.warning (source_reference, "`override' not required to implement `abstract' 
interface method `%s'".printf (base_interface_method.get_full_name ()));
+                       overrides = false;
                } else if (overrides && base_method == null && base_interface_method == null) {
                        Report.error (source_reference, "`%s': no suitable method found to override".printf 
(get_full_name ()));
                } else if ((is_abstract || is_virtual || overrides) && access == SymbolAccessibility.PRIVATE) 
{


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]