After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 622570 - Allow out/ref parameters in lambda expressions
Allow out/ref parameters in lambda expressions
Status: RESOLVED FIXED
Product: vala
Classification: Core
Component: Structs
unspecified
Other Linux
: Normal normal
: ---
Assigned To: Vala maintainers
Vala maintainers
: 574403 645838 (view as bug list)
Depends on:
Blocks: 589968
 
 
Reported: 2010-06-24 09:13 UTC by Luca Bruno
Modified: 2017-12-13 19:22 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
fix copying delegate parmaters for lambda expressions (1.64 KB, patch)
2010-06-24 09:58 UTC, Luca Bruno
none Details | Review
Support reference and output lambda parameters (9.55 KB, patch)
2010-07-12 22:32 UTC, Luca Bruno
none Details | Review
Support ref and out parameters in lambda expressions (9.98 KB, patch)
2011-04-16 10:56 UTC, Luca Bruno
accepted-commit_now Details | Review

Description Luca Bruno 2010-06-24 09:13:01 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;
}
Comment 1 Luca Bruno 2010-06-24 09:58:36 UTC
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.
Comment 2 Jürg Billeter 2010-07-12 19:11:28 UTC
Shouldn't we require the user to specify 'out' and 'ref' in those cases?
Comment 3 Luca Bruno 2010-07-12 22:32:21 UTC
Created attachment 165765 [details] [review]
Support reference and output lambda parameters
Comment 4 Luca Bruno 2010-07-12 22:33:15 UTC
(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?
Comment 5 Luca Bruno 2011-04-16 10:56:36 UTC
Created attachment 186067 [details] [review]
Support ref and out parameters in lambda expressions

Fixes bug 622570.
Comment 6 Luca Bruno 2011-05-11 09:54:54 UTC
*** Bug 645838 has been marked as a duplicate of this bug. ***
Comment 7 Jürg Billeter 2011-06-16 19:39:19 UTC
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.
Comment 8 Luca Bruno 2011-06-17 19:58:26 UTC
(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().
Comment 9 Maciej (Matthew) Piechotka 2011-06-17 20:00:35 UTC
(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 {
         ....
    }
    ....
}
Comment 10 Luca Bruno 2011-06-17 20:19:25 UTC
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().
Comment 11 Rico Tzschichholz 2017-12-13 19:22:35 UTC
*** Bug 574403 has been marked as a duplicate of this bug. ***