Bug 11774 – Lambda argument to templated function changes its signature forever
Status
RESOLVED
Resolution
FIXED
Severity
major
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-12-19T06:53:00Z
Last change time
2014-05-26T17:32:01Z
Keywords
pull, rejects-valid
Assigned to
nobody
Creator
verylonglogin.reg
Comments
Comment #0 by verylonglogin.reg — 2013-12-19T06:53:48Z
This code should compile:
---
void f(T, R)(R delegate(T[]) del)
{
T[] src;
del(src);
}
void main()
{
int[] delegate(int[]) del;
f!int(del); // ok
f!Object(a => a);
f!int(del); // fails, line 12
}
---
main.d(12): Error: template main.f does not match any function template declaration. Candidates are:
main.d(1): main.f(T, R)(R delegate(Object[]) del)
main.d(12): Error: template main.f(T, R)(R delegate(Object[]) del) cannot deduce template function from argument types !(int)(int[] delegate(int[]))
---
The issue is major as compiler errors are misleading and people don't expect such "broken forever" behaviour.
Comment #1 by verylonglogin.reg — 2013-12-19T06:55:27Z
Workaround:
Specify lambda argument types, i.e. `(Object[] a) => a` instead of `a => a`.