struct MyStruct {}

void main(string[] args) {
        string str = "blah-blah";

        auto d1 = (MyStruct) { writeln("delegate-str: ", str); };

        writeln(typeid(typeof(d1)));
}



dmd: 2067
os: Win8.1
build script: dmd main.d -ofconsole-app.exe -debug -unittest -wi

- if delegate has no params or param is declared as int/char/float then the code compiles successfully.
        auto d1 = (int) { writeln("delegate-str: ", str); };

- if I declare named param as string or MyStruct then the code compiles successfully too.
        auto d1 = (MyStruct ms)  { writeln("delegate-str: ", str); };

- if I declare anonymous parameter as string or MyStruct then the error compile occurs:
        auto d1 = (MyStruct)  { writeln("delegate-str: ", str); };

main.d(21): Error: variable main.main.d1 type void is inferred from initializer (MyStruct)

{

writeln("delegate-str: ", str);

}

, and variables cannot be of type void
main.d(21): Error: template lambda has no value

Why does it happen?

Reply via email to