[Issue 2939] lazy evaluation not invoked for lambda function

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon May 4 22:16:36 PDT 2009


http://d.puremagic.com/issues/show_bug.cgi?id=2939





------- Comment #1 from jarrett.billingsley at gmail.com  2009-05-05 00:16 -------
The foreach loop is actually not important.

void f(lazy void dg)
{
        dg();
}

void main()
{
        void foo() { Stdout.formatln("o hai"); }
        f(foo);
        f({Stdout.formatln("lol wut");});
}

Only 'o hai' is printed, 'lol wut' never makes it.

In order to make it work, you have to put parens after the lambda:

f({Stdout.formatln("lol wut");}());

I'm not justifying the compiler's behavior :{ but that's the workaround I've
been using.


-- 



More information about the Digitalmars-d-bugs mailing list