GNOME Bugzilla – Bug 606478
Lambda return values not handled correctly in some coses
Last modified: 2010-01-31 21:10:09 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"); }
Created attachment 152161 [details] [review] Start analyzing lambda flow Help bug 606478.
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; ^^^^^
Created attachment 152176 [details] [review] Start analyzing lambda flow Help bug 606478.
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.
Looks like the patch is working, but the error message doesnt specified the file:line. Thanks!
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.
*** Bug 601667 has been marked as a duplicate of this bug. ***