[vala/staging] codegen: Infer error parameter from abstract/virtual method implementations



commit 527dac8050fe90d7a28619383f11e968ab5c9a77
Author: Rico Tzschichholz <ricotz ubuntu com>
Date:   Sat Jan 27 13:23:53 2018 +0100

    codegen: Infer error parameter from abstract/virtual method implementations
    
    https://bugzilla.gnome.org/show_bug.cgi?id=614294

 codegen/valaccodemethodcallmodule.vala |    3 ++
 codegen/valaccodemethodmodule.vala     |    2 +-
 tests/Makefile.am                      |    1 +
 tests/asynchronous/bug614294.vala      |   59 ++++++++++++++++++++++++++++++++
 vala/valamethod.vala                   |   13 +++++++
 5 files changed, 77 insertions(+), 1 deletions(-)
---
diff --git a/codegen/valaccodemethodcallmodule.vala b/codegen/valaccodemethodcallmodule.vala
index bfcc215..3fadb27 100644
--- a/codegen/valaccodemethodcallmodule.vala
+++ b/codegen/valaccodemethodcallmodule.vala
@@ -625,6 +625,9 @@ public class Vala.CCodeMethodCallModule : CCodeAssignmentModule {
                        current_method_inner_error = true;
                        // add &inner_error before the ellipsis arguments
                        out_arg_map.set (get_param_pos (-1), new CCodeUnaryExpression 
(CCodeUnaryOperator.ADDRESS_OF, get_variable_cexpression ("_inner_error_")));
+               } else if (m != null && m.has_error_type_parameter ()) {
+                       // inferred error argument from base method
+                       out_arg_map.set (get_param_pos (-1), new CCodeConstant ("NULL"));
                }
 
                if (ellipsis) {
diff --git a/codegen/valaccodemethodmodule.vala b/codegen/valaccodemethodmodule.vala
index 33c5ee4..1b9c677 100644
--- a/codegen/valaccodemethodmodule.vala
+++ b/codegen/valaccodemethodmodule.vala
@@ -110,7 +110,7 @@ public abstract class Vala.CCodeMethodModule : CCodeStructModule {
                        }
                }
 
-               if (m.get_error_types ().size > 0 || (m.base_method != null && m.base_method.get_error_types 
().size > 0) || (m.base_interface_method != null && m.base_interface_method.get_error_types ().size > 0)) {
+               if (m.has_error_type_parameter ()) {
                        foreach (DataType error_type in m.get_error_types ()) {
                                generate_type_declaration (error_type, decl_space);
                        }
diff --git a/tests/Makefile.am b/tests/Makefile.am
index aba0612..77acc32 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -285,6 +285,7 @@ TESTS = \
        asynchronous/bug600827.vala \
        asynchronous/bug601558.vala \
        asynchronous/bug613484.vala \
+       asynchronous/bug614294.vala \
        asynchronous/bug620740.vala \
        asynchronous/bug639591.vala \
        asynchronous/bug640721.vala \
diff --git a/tests/asynchronous/bug614294.vala b/tests/asynchronous/bug614294.vala
new file mode 100644
index 0000000..34c50a2
--- /dev/null
+++ b/tests/asynchronous/bug614294.vala
@@ -0,0 +1,59 @@
+interface IFoo : Object {
+       public abstract async void foo_async () throws Error;
+       public abstract void foo () throws Error;
+}
+
+class Bar : Object, IFoo {
+       public virtual async void foo_async () {
+       }
+       public virtual void foo () {
+       }
+}
+
+class SubBar : Bar {
+       public override async void foo_async () {
+       }
+       public override void foo () {
+       }
+}
+
+abstract class AFoo : Object {
+       public abstract async void foo_async () throws Error;
+       public abstract void foo () throws Error;
+}
+
+class Baz : AFoo {
+       public override async void foo_async () {
+       }
+       public override void foo () {
+       }
+}
+
+class SubBaz : Baz {
+       public override async void foo_async () {
+       }
+       public override void foo () {
+       }
+}
+
+async void run () {
+       var bar = new Bar ();
+       bar.foo ();
+       yield bar.foo_async ();
+
+       var subbar = new SubBar ();
+       subbar.foo ();
+       yield subbar.foo_async ();
+
+       var baz = new Baz ();
+       baz.foo ();
+       yield bar.foo_async ();
+
+       var subbaz = new SubBaz ();
+       subbaz.foo ();
+       yield subbaz.foo_async ();
+}
+
+void main () {
+       run.begin ();
+}
diff --git a/vala/valamethod.vala b/vala/valamethod.vala
index 66c131b..8af2f66 100644
--- a/vala/valamethod.vala
+++ b/vala/valamethod.vala
@@ -1083,6 +1083,19 @@ public class Vala.Method : Subroutine, Callable {
                }
                return -1;
        }
+
+       public bool has_error_type_parameter () {
+               if (get_error_types ().size > 0) {
+                       return true;
+               }
+               if (base_method != null && base_method != this && base_method.has_error_type_parameter ()) {
+                       return true;
+               }
+               if (base_interface_method != null && base_interface_method != this && 
base_interface_method.has_error_type_parameter ()) {
+                       return true;
+               }
+               return false;
+       }
 }
 
 // vim:sw=8 noet


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