Bug 301 – Lazy Delegate Evaluation messes with writefln

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D1 (retired)
Platform
x86
OS
Windows
Creation time
2006-08-21T00:59:00Z
Last change time
2014-02-15T13:18:40Z
Keywords
wrong-code
Assigned to
bugzilla
Creator
ddparnell

Comments

Comment #0 by ddparnell — 2006-08-21T00:59:53Z
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"
Comment #1 by bugzilla — 2006-09-02T19:45:49Z
Fixed 0.166