]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
codegen: Don't falsly use g_return_val_if_fail() for async creation method
authorRico Tzschichholz <ricotz@ubuntu.com>
Sun, 27 Sep 2020 08:38:41 +0000 (10:38 +0200)
committerRico Tzschichholz <ricotz@ubuntu.com>
Sun, 27 Sep 2020 08:52:55 +0000 (10:52 +0200)
Asynchronous creation methods are represented by 5 functions, "*_new",
"*_new_finish", "*_construct", "*_construct_co" and "*_construct_finish".
The argument checks are emitted in "*_construct" which is a void function
and cannot return any value.

Regression of 43f3e2ca534d082433fbe62aa347b7af443f9f33

Fixes https://gitlab.gnome.org/GNOME/vala/issues/1077

codegen/valagtypemodule.vala
tests/Makefile.am
tests/asynchronous/constructor-argument-check.vala [new file with mode: 0644]

index daaa22b3a18c1725008e910f200c017449e337d2..8a8862a71afe052f894aca00a236627744fca68b 100644 (file)
@@ -2410,7 +2410,7 @@ public class Vala.GTypeModule : GErrorModule {
                cfile.add_include ("glib.h");
 
                var cm = method_node as CreationMethod;
-               if (cm != null && cm.parent_symbol is ObjectTypeSymbol) {
+               if (cm != null && !cm.coroutine && cm.parent_symbol is ObjectTypeSymbol) {
                        ccheck.call = new CCodeIdentifier ("g_return_val_if_fail");
                        ccheck.add_argument (new CCodeConstant ("NULL"));
                } else if (ret_type is VoidType) {
index 817080efed55fe615718149a37722a46a1893f3f..de02d16076b9f77aab2bd78955b77909b2b0382c 100644 (file)
@@ -597,6 +597,7 @@ TESTS = \
        asynchronous/catch-in-finally.vala \
        asynchronous/creation-missing-yield.test \
        asynchronous/closures.vala \
+       asynchronous/constructor-argument-check.vala \
        asynchronous/finish-name.vala \
        asynchronous/generator.vala \
        asynchronous/out-parameter-invalid.test \
diff --git a/tests/asynchronous/constructor-argument-check.vala b/tests/asynchronous/constructor-argument-check.vala
new file mode 100644 (file)
index 0000000..2223810
--- /dev/null
@@ -0,0 +1,13 @@
+class Foo {
+       public async Foo (string bar) {
+               assert (bar == "foo");
+       }
+}
+
+async void run () {
+       yield new Foo ("foo");
+}
+
+void main () {
+       run.begin ();
+}