From: Rico Tzschichholz Date: Sun, 27 Sep 2020 08:38:41 +0000 (+0200) Subject: codegen: Don't falsly use g_return_val_if_fail() for async creation method X-Git-Tag: 0.50.1~10 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=07057c8cdd164223b70eafbef8b1db096df97974;p=thirdparty%2Fvala.git codegen: Don't falsly use g_return_val_if_fail() for async creation method 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 --- diff --git a/codegen/valagtypemodule.vala b/codegen/valagtypemodule.vala index daaa22b3a..8a8862a71 100644 --- a/codegen/valagtypemodule.vala +++ b/codegen/valagtypemodule.vala @@ -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) { diff --git a/tests/Makefile.am b/tests/Makefile.am index 817080efe..de02d1607 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -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 index 000000000..22238108a --- /dev/null +++ b/tests/asynchronous/constructor-argument-check.vala @@ -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 (); +}