]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
codegen: Infer error parameter from abstract/virtual method implementations
authorRico Tzschichholz <ricotz@ubuntu.com>
Sat, 27 Jan 2018 12:23:53 +0000 (13:23 +0100)
committerRico Tzschichholz <ricotz@ubuntu.com>
Tue, 30 Jan 2018 07:15:24 +0000 (08:15 +0100)
https://bugzilla.gnome.org/show_bug.cgi?id=614294

codegen/valaccodemethodcallmodule.vala
codegen/valaccodemethodmodule.vala
tests/Makefile.am
tests/asynchronous/bug614294.vala [new file with mode: 0644]
vala/valamethod.vala

index 3c3b73223bebfb62c90729eba5e964a614fe223b..2212814bedbd5bcfb0d7d02f4afb8511e2d4e6d8 100644 (file)
@@ -615,6 +615,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) {
index 7f13602e097271a23fdf237ce197bbd73f1c05fe..974565c7f464756d2946dcecf401f9a99d9234d0 100644 (file)
@@ -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);
                        }
index b79f7ec5c2958e6cf06ee7ec400a729bfd49a6c4..45c3a3a47c72ddee54a3323f1dc3cd2af3793efa 100644 (file)
@@ -222,6 +222,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 (file)
index 0000000..34c50a2
--- /dev/null
@@ -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 ();
+}
index 93dd857938a4451a0a8f68c5584156aa7d72d2be..994f83dc2c8ffa32acbd4e12d6c9b4b822c97bfc 100644 (file)
@@ -1077,6 +1077,19 @@ public class Vala.Method : Subroutine {
                }
        }
 
+       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;
+       }
+
        private static string type_to_prototype_string (DataType type) {
                return "%s%s".printf (type.is_weak () ? "unowned " : "", type.to_qualified_string ());
        }