Bug 6260 – [Memory Corruption] Passed around lazy arguments don't work with closures

Status
RESOLVED
Resolution
INVALID
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2011-07-06T13:29:00Z
Last change time
2011-12-28T09:53:56Z
Keywords
wrong-code
Assigned to
nobody
Creator
timon.gehr

Comments

Comment #0 by timon.gehr — 2011-07-06T13:29:26Z
Tested in DMD 2.053: auto foo(lazy int x){return {return x;};} auto bar(lazy int x){return foo(x);} void main(){assert(foo(1)()==bar(1)());} // assertion failure Workaround: auto foo(lazy int x){return {return x;};} auto bar(lazy int x){return foo({return x;}());} // destroy purpose of 'lazy' void main(){assert(foo(1)()==bar(1)());} // pass Some funny stuff: import std.stdio; void main(){ auto x=bar(1); writeln(x()); } writes: <Garbage integer value> 0 Where does "0" come from? void main(){ writeln(bar(1)()); } writes: <Garbage integer value> Segmentation Fault
Comment #1 by timon.gehr — 2011-12-28T09:53:56Z
lazy arguments are implicitly scoped, so this is by design.