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.