class A
{
A next;
static void fun(alias fun)(A n)
{
assert(0);
}
static void gun()
{
void hun(A a)
{
}
fun!(hun)(next);
}
}
Even after making all functions static, the code does not work with the error:
template instance cannot use local 'hun' as parameter to non-global template fun(alias fun)
Comment #1 by hoganmeier — 2011-07-14T01:02:14Z
This is because dmd checks in TemplateInstance::hasNestedArgs that the template declaration is in module scope:
if (tempdecl->toParent()->isModule())
And with a little hack:
// if module level template or a static member of an aggregate
// NOTE not sure if there is a better way to determine the storage class of a templated class method
if (tempdecl->toParent()->isModule() || (tempdecl->isMember() && tempdecl->scope->stc & STCstatic))
we get
Error: need 'this' to access member next
Comment #2 by dkorpel — 2019-06-26T13:03:22Z
Up to 2.064 the error was indeed "template instance fun!(hun) cannot use local 'hun' as parameter to non-global template fun(alias fun)(A n)"
Since 2.065 it says:
onlineapp.d(15): Error: need 'this' for 'next' of type 'onlineapp.A'
Which is true, since gun is a static function and `next` a member variable.