www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 301] New: Lazy Delegate Evaluation messes with writefln

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=301

           Summary: Lazy Delegate Evaluation messes with writefln
           Product: D
           Version: 0.165
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla digitalmars.com
        ReportedBy: ddparnell bigpond.com


The following compiles but the output is wrong.
// ---------- TEST FILE ---------
import std.stdio;
bool scase(bool b, void delegate() dg)
{
    if (b)
    {   dg();
        return true;
    }
    return false;
}

void cond(bool delegate()[] cases ...)
{
    foreach (c; cases)
    {   if (c())
            break;
    }
}


void foo()
{
    int v = 2;
    cond
    (
        scase(v == 1, {writefln("it is 1");}),
        scase(v == 2, {writefln("it is 2");}),
        scase(v == 3, {writefln("it is 3");}),
        scase(true,   {writefln("it is the default");})
    );
}
void main()
{
    foo();
}
// ---------- END OF TEST FILE ---------

The output is ...
"[char[]]it is 2"
instead of the expected ...
"it is 2"


-- 
Aug 20 2006
parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=301


bugzilla digitalmars.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED





Fixed 0.166


-- 
Sep 02 2006