Bug 8560 – Strange behavior of lambda expressions

Status
RESOLVED
Resolution
INVALID
Severity
major
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2012-08-18T13:45:00Z
Last change time
2012-08-18T13:57:54Z
Assigned to
nobody
Creator
iu.biryukov

Comments

Comment #0 by iu.biryukov — 2012-08-18T13:45:45Z
I came up with this code while playing around with D: import std.stdio; public class Test(alias fun, alias fun2) { void doIt() { fun(); fun2(); } } void main() { (new Test!( () => {writeln("fun1");}, () => writeln("fun2") ) ).doIt(); } After compiling this code I expect to see the following output(or compiler error, if I'm misusing lambda syntax): fun1 fun2 Insted I get: fun2 DMD64 D Compiler v2.060
Comment #1 by code — 2012-08-18T13:48:30Z
Marking as invalid, since {writeln("fun1");} is a parameterless delegate literal. This delegate is returned by the call to fun(), but never invoked.
Comment #2 by iu.biryukov — 2012-08-18T13:55:08Z
(In reply to comment #1) > Marking as invalid, since {writeln("fun1");} is a parameterless delegate > literal. This delegate is returned by the call to fun(), but never invoked. Thanks, now I get it. Though this behavior looks a bit odd to me. But that's probably because of C# background.
Comment #3 by code — 2012-08-18T13:57:54Z
(In reply to comment #2) > Though this behavior looks a bit odd to me. But that's probably because of C# > background. Mhm, even if the current behavior is to spec, it can definitely be surprising. If you feel something should be done about this, please consider starting a discussion on the forums.