GNOME Bugzilla – Bug 646345
Vala generates invalid C code with some lambda functions
Last modified: 2011-04-02 13:49:01 UTC
Created attachment 184786 [details] list.vala Vala 0.11.7.31-c46029 (git master) With the attached file: $ valac list.vala list.vala.c: In function ‘_lambda1_’: list.vala.c:321: error: ‘_data1_’ undeclared (first use in this function) The bogus generated C code is: static void _lambda1_ (GList* added, MyTest* self) { Block2Data* _data2_; gconstpointer _tmp0_ = NULL; Individual* _tmp1_; _data2_ = g_slice_new0 (Block2Data); _data2_->_ref_count_ = 1; _data2_->_data1_ = block1_data_ref (_data1_); <----HERE _tmp0_ = g_list_nth_data (added, (guint) 0); _tmp1_ = _g_object_ref0 ((Individual*) _tmp0_); _data2_->i = _tmp1_; g_idle_add_full (G_PRIORITY_DEFAULT_IDLE, __lambda2__gsource_func, block2_data_ref (_data2_), block2_data_unref); block2_data_unref (_data2_); _data2_ = NULL; }
Shorter test case: void main() { var outervar = "outerfoo"; SourceFunc firstfunc = () => { outervar = "outerbar"; }; SourceFunc secondfunc = () => { var innervar = "innerfoo"; SourceFunc innerfunc = () => { innervar = "innerbar"; }; }; } If I'm not wrong, the problem is that neither secondfunc nor innerfunc refer to the parent captured block (e.g. using outervar), therefore it's missing the _data1_ block as parameter. Workaround is to reference some variable of the parent block. The fix should be to not reference the unused parent block.
Created attachment 184933 [details] [review] codegen: Fix looking up next closure block Methods that are not closures don't capture parent blocks. Fixes bug 646345.
commit a90b9d2e467ab77ccef7bcd6c26f310cda3b6f2f Author: Luca Bruno <lucabru@src.gnome.org> Date: Sat Apr 2 10:09:10 2011 +0200 codegen: Fix look-up of next closure block Methods that are not closures don't capture parent blocks. Fixes bug 646345.