www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 3052] New: Passing alias to member function does not work (2/2)

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3052

           Summary: Passing alias to member function does not work (2/2)
           Product: D
           Version: unspecified
          Platform: Other
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla digitalmars.com
        ReportedBy: andrei metalanguage.com


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)

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jun 04 2009
parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3052


Trass3r <mrmocool gmx.de> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |mrmocool gmx.de



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

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jul 14 2011