Disallow braced lambda after =>. Concrete, for the D grammar people, if in a Lambda the arrow is followed by a FunctionLiteral which is just a FunctionLiteralBody, this will be an error. It applies not when the function after => is called, e.g. (..) => { .. }(), because then the "thing" after => is a PostfixExpression (as is any function call), not a FunctionLiteralBody.[1] This would prevent many C# newbie errors. It is almost never correct. The workarounds are simple: 1. Use () before the brace. 2. Use function/delegate before the brace 3. Use braces instead of =>, e.g. (..) { return { .. }; } instead of (..) => { .. } The compiler should warn you that => { .. } introduces two nested lambdas and because probably one actually wants just one, suggests to delete the arrow. In case of desired nested lambdas, the recommended fix is 2. to make it obvious to anyone reading the code. Option 1. is possible but not that desirable. Option 3 should definitely not be recommended by the compiler as it is very lengthy. [1] https://dlang.org/spec/expression.html#FunctionLiteral As this is potentially breaking code, we'd need the full deprecation process. Fortunately, nested lambdas are rarely used, so the amount of broken code is small if any.
The issue is being discussed on the forum regularly by newcomers and even regular D users. I didn't search for them myself, but here are some: https://forum.dlang.org/thread/ecwfiderxbfqzjcyymkg@forum.dlang.org https://forum.dlang.org/thread/ihsmxiplprxwlqkgwswc@forum.dlang.org https://forum.dlang.org/thread/qsayoktyffczskrnmgxu@forum.dlang.org
*** This issue has been marked as a duplicate of issue 16001 ***