GNOME Bugzilla – Bug 622570
Allow out/ref parameters in lambda expressions
Last modified: 2017-12-13 19:22:35 UTC
Hello, this is the test case: delegate void TestDelegate (out Value foo); void test (TestDelegate d) { } void main () { test ((foo) => { foo = (int) 0; }); } Generated code, last line must not be there: static void _lambda0_ (GValue* foo) { GValue _tmp1_; GValue _tmp0_ = {0}; *foo = (_tmp1_ = (g_value_init (&_tmp0_, G_TYPE_INT), g_value_set_int (&_tmp0_, (gint) 0), _tmp0_), G_IS_VALUE (foo) ? (g_value_unset (foo), NULL) : NULL, _tmp1_); G_IS_VALUE (&foo) ? (g_value_unset (&foo), NULL) : NULL; }
Created attachment 164484 [details] [review] fix copying delegate parmaters for lambda expressions This way lambdas will support out/ref/owned parameters. Beware the test is not useful, because I can't get it to a crash, it only spits warnings.
Shouldn't we require the user to specify 'out' and 'ref' in those cases?
Created attachment 165765 [details] [review] Support reference and output lambda parameters
(In reply to comment #3) > Created an attachment (id=165765) [details] [review] > Support reference and output lambda parameters Notice, parser is broken for out/ref parameters because of parse_tuple. What's the best way to support this?
Created attachment 186067 [details] [review] Support ref and out parameters in lambda expressions Fixes bug 622570.
*** Bug 645838 has been marked as a duplicate of this bug. ***
Review of attachment 186067 [details] [review]: The patch looks fine to me, I assume the tests are passing. Just two tiny things: ::: vala/valacodewriter.vala @@ +1905,3 @@ + int i = 1; + foreach (var param in params) { + if (i > 1) { Normally, we start counting from 0 in such situations, or am I missing something? ::: vala/valamethodtype.vala @@ -55,3 @@ return false; } - Unrelated whitespace change.
(In reply to comment #7) > ::: vala/valacodewriter.vala > @@ +1905,3 @@ > + int i = 1; > + foreach (var param in params) { > + if (i > 1) { > > Normally, we start counting from 0 in such situations, or am I missing > something? That's only for not writing "," for the first parameter. I just copied the code from write_params().
(In reply to comment #8) > (In reply to comment #7) > > ::: vala/valacodewriter.vala > > @@ +1905,3 @@ > > + int i = 1; > > + foreach (var param in params) { > > + if (i > 1) { > > > > Normally, we start counting from 0 in such situations, or am I missing > > something? > > That's only for not writing "," for the first parameter. I just copied the code > from write_params(). Shouldn't it be: bool first = true; foreach(var param in params) { if (first) { first = !first; } else { .... } .... }
commit 3ee508f5fdf332978848d344049bdeeb3fbe741a Author: Luca Bruno <lucabru@src.gnome.org> Date: Sat Apr 16 12:55:35 2011 +0200 Support ref and out parameters in lambda expressions Fixes bug 622570. (In reply to comment #9) > Shouldn't it be: > > bool first = true; > > foreach(var param in params) { > if (first) { > first = !first; > } else { > .... > } > .... > } It's equivalent. I just used the same code of write_params().
*** Bug 574403 has been marked as a duplicate of this bug. ***