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 646345 - Vala generates invalid C code with some lambda functions
Vala generates invalid C code with some lambda functions
Status: RESOLVED FIXED
Product: vala
Classification: Core
Component: Methods
0.11.x
Other Linux
: Urgent normal
: ---
Assigned To: Vala maintainers
Vala maintainers
test-case invalid-c-code
Depends on:
Blocks:
 
 
Reported: 2011-03-31 14:36 UTC by Alban Crequy
Modified: 2011-04-02 13:49 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
list.vala (808 bytes, text/x-vala)
2011-03-31 14:36 UTC, Alban Crequy
  Details
codegen: Fix looking up next closure block (2.64 KB, patch)
2011-04-02 08:21 UTC, Luca Bruno
none Details | Review

Description Alban Crequy 2011-03-31 14:36:26 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;
}
Comment 1 Luca Bruno 2011-04-02 07:27:40 UTC
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.
Comment 2 Luca Bruno 2011-04-02 08:21:42 UTC
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.
Comment 3 Jürg Billeter 2011-04-02 13:49:01 UTC
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.