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 606478 - Lambda return values not handled correctly in some coses
Lambda return values not handled correctly in some coses
Status: RESOLVED FIXED
Product: vala
Classification: Core
Component: Semantic Analyzer
unspecified
Other Linux
: Normal blocker
: ---
Assigned To: Vala maintainers
Vala maintainers
: 601667 (view as bug list)
Depends on:
Blocks:
 
 
Reported: 2010-01-09 11:45 UTC by pancake
Modified: 2010-01-31 21:10 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Start analyzing lambda flow (2.56 KB, patch)
2010-01-24 17:41 UTC, Marc-Andre Lureau
none Details | Review
Start analyzing lambda flow (3.70 KB, patch)
2010-01-24 20:33 UTC, Marc-Andre Lureau
none Details | Review
Start analyzing flow inside lambda expressions (4.01 KB, patch)
2010-01-25 00:54 UTC, Marc-Andre Lureau
none Details | Review

Description pancake 2010-01-09 11:45:49 UTC
The following code generates a lambda with no return value which results in a warning at C level (Only with -Wall). So with default compile options (valac foo.vala, or gcc without -Wall) you get no feedback about the issue.

This bug causes the function to return trash values, that can result in crashes, so this should be an error.

-------------------- 
delegate int FoodCallback (int x);

int food (FoodCallback cb) {
        return cb (0);
}


int main () {
        return food ((x) => {
                print ("Hello World\n");
                //return 1;
        });
}
--------------------

The resulting wrong code is:

static gint _lambda0_ (gint x) {
        gint result;
        g_print ("Hello World\n");
}
Comment 1 Marc-Andre Lureau 2010-01-24 17:41:47 UTC
Created attachment 152161 [details] [review]
Start analyzing lambda flow

Help bug 606478.
Comment 2 Marc-Andre Lureau 2010-01-24 17:43:23 UTC
This is not final fix, it fails to compile:
void main () {
    int i = 42;
    do_foo (() => {
			do_foo (() => {
					int j = i;
				});
		});
}


with:

test.vala:11.10-11.14: warning: local variable `j' declared but never used
					int j = i;
					    ^^^^^
test.vala:11.10-11.14: error: use of possibly unassigned local variable `i'
					int j = i;
					    ^^^^^
Comment 3 Marc-Andre Lureau 2010-01-24 20:33:21 UTC
Created attachment 152176 [details] [review]
Start analyzing lambda flow

Help bug 606478.
Comment 4 Marc-Andre Lureau 2010-01-25 00:54:02 UTC
Created attachment 152190 [details] [review]
Start analyzing flow inside lambda expressions

get_defined_variables() might be wrongly added,
we could add a FakeCodeNode class with the
defined variables if it's the case.

Fixes bug 606478.
Comment 5 pancake 2010-01-25 12:34:17 UTC
Looks like the patch is working, but the error message doesnt specified the file:line.

Thanks!
Comment 6 Jürg Billeter 2010-01-29 21:03:10 UTC
commit da67841f1fed0b391965e6c1b2179855396ab06b
Author: Marc-André Lureau <marcandre.lureau@gmail.com>
Date:   Sun Jan 24 18:41:44 2010 +0100

    Perform flow analysis on lambda expressions
    
    Fixes bug 606478.
Comment 7 Evan Nemerson 2010-01-31 21:10:09 UTC
*** Bug 601667 has been marked as a duplicate of this bug. ***