Bug 16404 – Funky type for parameterless lambdas () => { ... }
Status
RESOLVED
Resolution
INVALID
Severity
major
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2016-08-19T18:41:00Z
Last change time
2016-08-19T20:11:04Z
Assigned to
nobody
Creator
kinke
Comments
Comment #0 by kinke — 2016-08-19T18:41:53Z
```
void bar(void function() f) {}
void bar(void delegate() d) {}
void foo()
{
int i;
bar(() => {});
bar(() => { ++i; });
}
```
Output with DMD nightly:
```
M.d(7): Error: none of the overloads of 'bar' are callable using argument types (void function() pure nothrow @nogc @safe function() pure nothrow @nogc @safe), candidates are:
M.d(1): M.bar(void function() f)
M.d(2): M.bar(void delegate() d)
M.d(8): Error: none of the overloads of 'bar' are callable using argument types (void delegate() pure nothrow @nogc @safe delegate() pure nothrow @nogc @safe), candidates are:
M.d(1): M.bar(void function() f)
M.d(2): M.bar(void delegate() d)
```
Comment #1 by cauterite — 2016-08-19T18:45:53Z
i think you made the mistake of writing
() => {}
when you actually mean
() {}
the compiler interprets `() => {}` as a lambda which returns another lambda `{}`
not to be confused with the same syntax in JavaScript, which works the way you expected it to work here.