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 683925 - If you declare a delegate with a default value, the closure for that default value is broken.
If you declare a delegate with a default value, the closure for that default ...
Status: RESOLVED FIXED
Product: vala
Classification: Core
Component: Delegates
0.17.x
Other Linux
: Normal normal
: ---
Assigned To: Vala maintainers
Vala maintainers
Depends on:
Blocks:
 
 
Reported: 2012-09-13 07:32 UTC by Javier Casas
Modified: 2017-03-22 16:08 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
codegen: Fix delegate initializer for instance fields (2.39 KB, patch)
2017-03-22 15:44 UTC, Rico Tzschichholz
committed Details | Review

Description Javier Casas 2012-09-13 07:32:26 UTC
If you declare a delegate with a default value, the closure for that default value is broken. See this code:



class Test_delegates : Object {
    public delegate string delegateType1(string param);


    public delegateType1 mydelegate=defaultfun; //This default initialization is badly made. The closure does not include the current instance of Test_delegates

    public Test_delegates(){
        //mydelegate = defaultfun; //This initialization works. Uncomment to see it working.
    }

    public string defaultfun(string param){
        stdout.printf("defaultfun received %s\n", param);
        string retorno = "### %s ###".printf(param);
        stdout.printf("defaultfun returns %s\n", retorno);
        return retorno;
    }

    public string otherfun(string param){
        stdout.printf("otherfun received %s\n", param);
        string retorno = "@@@ %s @@@".printf(param);
        stdout.printf("otherfun returns %s\n", retorno);
        return retorno;
    }

    public void run(){
        string result = mydelegate("blebleble");
        stderr.flush();
        stdout.printf("mydelegate returned %s\n", result);
        mydelegate=otherfun;
        result = mydelegate("blebleble");
        stdout.printf("mydelegate returned %s\n", result);
    }
}


void main(){
    var t1=new Test_delegates();
    t1.run();
}



Shows:
** (process:8090): CRITICAL **: test_delegates_defaultfun: assertion `self != NULL' failed
Comment 1 Rico Tzschichholz 2017-03-22 15:44:26 UTC
Created attachment 348513 [details] [review]
codegen: Fix delegate initializer for instance fields

Set delegate-target to "self" which is available in *_instance_init().
Comment 2 Rico Tzschichholz 2017-03-22 16:08:09 UTC
Attachment 348513 [details] pushed as db6f68f - codegen: Fix delegate initializer for instance fields