]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
codegen: Add implicit parameter and instance checks in async method 43f3e2ca534d082433fbe62aa347b7af443f9f33
authorRico Tzschichholz <ricotz@ubuntu.com>
Tue, 9 Jun 2020 14:22:17 +0000 (16:22 +0200)
committerRico Tzschichholz <ricotz@ubuntu.com>
Tue, 9 Jun 2020 15:04:27 +0000 (17:04 +0200)
This is already done for every non-async method and can be disabled by
passing --disable-assert.

See https://gitlab.gnome.org/GNOME/vala/issues/1005

codegen/valagasyncmodule.vala

index 7a545ea92f917425dbe0404a6105f683cd3e1e2b..6705fab98a387509a05dcd4ed9ba577746d4a76c 100644 (file)
@@ -180,6 +180,27 @@ public class Vala.GAsyncModule : GtkModule {
 
                push_function (asyncfunc);
 
+               // FIXME partial code duplication with CCodeMethodModule.visit_method
+               unowned Class? cl = m.parent_symbol as Class;
+               if (cl != null) {
+                       if (m.binding == MemberBinding.INSTANCE && !(m is CreationMethod)
+                           && m.base_method == null && m.base_interface_method == null) {
+                               create_type_check_statement (m, new VoidType (), cl, true, "self");
+                       }
+               }
+               foreach (Parameter param in m.get_parameters ()) {
+                       if (param.ellipsis || param.params_array) {
+                               break;
+                       }
+
+                       if (param.direction == ParameterDirection.IN) {
+                               unowned TypeSymbol? t = param.variable_type.type_symbol;
+                               if (t != null && (t.is_reference_type () || param.variable_type.is_real_struct_type ())) {
+                                       create_type_check_statement (m, new VoidType (), t, !param.variable_type.nullable, get_ccode_name (param));
+                               }
+                       }
+               }
+
                // logic copied from valaccodemethodmodule
                if (m.overrides || (m.base_interface_method != null && !m.is_abstract && !m.is_virtual)) {
                        Method base_method;