Deprecate {} without () for function pointers and delegates
ABrightLight
example at example.com
Fri Jun 12 21:07:49 UTC 2026
It's generally been agreed on in the past that {} without () in
lambdas causes ambiguity with block statements.
```
void foo (void delegate () dg) {
dg();
}
void main () {
auto dg = {1.writeln;}; // Works.
foo(dg); // function `foo` is not callable using argument types
`(void function() @safe)` (This is not entirely related but I
thought I'd point this out as something a bit odd)
{1.writeln;}(); // Error
}
```
These are the simpler cases where it could be a problem. But I
recently thought of `lazy`, and how expression-statements are
coerced to delegates under the hood, but what if you wanted to
pass a block statement to a function that takes `lazy`?
Anyway, I'd rather not have to juggle these questions in my mind,
and a simple solution would be to deprecate function literals
that omit the parentheses for the parameter list. Having to type
an extra 2 characters is well worth not having to think about the
edge cases.
Thank you
More information about the Digitalmars-d
mailing list