D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 11098 - template instance x cannot use local y as parameter to non-global template z
Summary: template instance x cannot use local y as parameter to non-global template z
Status: RESOLVED DUPLICATE of issue 5710
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P2 normal
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-09-22 07:04 UTC by simendsjo
Modified: 2018-02-16 13:50 UTC (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description simendsjo 2013-09-22 07:04:24 UTC
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 Ralph Tandetzky 2013-12-12 07:03:28 UTC
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 ryan 2015-05-23 19:34:29 UTC
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 Simen Kjaeraas 2018-02-16 13:50:34 UTC

*** This issue has been marked as a duplicate of issue 5710 ***