Bug 11098 – template instance x cannot use local y as parameter to non-global template z
Status
RESOLVED
Resolution
DUPLICATE
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-09-22T07:04:24Z
Last change time
2018-02-16T13:50:34Z
Assigned to
No Owner
Creator
simendsjo
Comments
Comment #0 by simendsjo — 2013-09-22T07:04:24Z
Using dmd head.
template A(T...) {
template B(alias T) { }
}
void main() {
void fv() {}
alias A!(fv) F;
F.B!F;
}
t.d(8): Error: template instance B!(A!(fv)) cannot use local
'A!(fv)' as parameter to non-global template B(alias T)
Comment #1 by ralph.tandetzky2 — 2013-12-12T07:03:28Z
I got the same problem with DMD64 D Compiler v2.063.2 on Linux Mint with the following minimal code example:
struct S
{
void f(alias F)()
{
}
}
void main()
{
S.init.f!( x=>x ); // << error
}
I get the following error message:
test.d(10): Error: template instance f!(__lambda2) cannot use local '__lambda2(__T1)(x)' as parameter to non-global template f(alias F)()
The UFCS form of f works though:
struct S
{
}
void f(alias F)( S )
{
}
void main()
{
S.init.f!( x=>x ); // << works
}
Comment #2 by ryan — 2015-05-23T19:34:29Z
This is still around in DMD2.067.
The UFCS trick is a nice work-around on the callee side.
You can also work around it on the caller side with:
struct S {
void f(alias F)() { }
}
void main() {
static int fun(int i) { return i; }
S.init.f!(fun);
}
Both are less than ideal though.
Comment #3 by simen.kjaras — 2018-02-16T13:50:34Z
*** This issue has been marked as a duplicate of issue 5710 ***