[Issue 2939] New: lazy evaluation not invoked for lambda function

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon May 4 21:49:28 PDT 2009


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

           Summary: lazy evaluation not invoked for lambda function
           Product: D
           Version: 2.029
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla at digitalmars.com
        ReportedBy: cristian at zerobugs.org


The following code illustrates how a lambda function is not evaluated when the
caller is inside of a foreach block.

class X
{
    int bogus;

    int opApply(int delegate(ref X) dg)
    {
        return dg(this);
    }
}

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

void main()
{
    bool ok = false;
    void okay() { ok = true; }
    X x = new X;
    foreach(elem; x)
    {
        f({ok = true;}); // ASSERTION WILL FAIL FOR LAMBDA
        //f (okay); // works okay for other functions
    }
    assert(ok);
}


-- 



More information about the Digitalmars-d-bugs mailing list