D has a few ways of writing lambda expressions / anonymous functions:

    x => doSomething()
    { doSomething(); }
    (){ doSomething(); }

While the flexibility is great, there's a hidden issue for those programmers who come from different languages and are used to writing:

    x => { doSomething(); doSomethingElse(); }

At first glance, this may seem okay but what's actually happening is that this is a lambda returning a lambda. The correct way would be to rewrite this as one of:

    x => { doSomething(); doSomethingElse(); }()
    (x){ doSomething(); doSomethingElse(); }

This particular issue as popped up twice in the last couple days alone and presumably many more times in the past:

http://forum.dlang.org/thread/qsayoktyffczskrnm...@forum.dlang.org
http://forum.dlang.org/thread/thgyqyarccinzuqhc...@forum.dlang.org

I'm proposing that we add a warning to the compiler for this particular case. If the programmer intended to return a lambda, then rewrite the expression as one of:

    x => (){ doSomething(); doSomethingElse(); }
    x => ({ doSomething(); doSomethingElse(); })

Reply via email to