On 2013-06-04 13:13, bearophile wrote:

If there are some things that don't give you enough static introspection
to perform that, then it's worth adding that missing static
introspection to D language.

It actually works. My mistake. Here's a version that works with modules as well:

void checkVirtual (alias T) ()
{
    static if (is(T == class))
    {
        foreach (m ; __traits(derivedMembers, T))
        {
alias TypeTuple!(__traits(getAttributes, mixin("T." ~ m))) attrs;
            enum methodName = T.stringof ~ "." ~ m.stringof;

            static if (staticIndexOf!(virtual, attrs) != -1)
            {
                static if (!__traits(isVirtualMethod, mixin("T." ~ m)))
static assert (false, "Method " ~ methodName ~ " marked as @virtual is not virtual");
            }

            else
            {
                static if (__traits(isVirtualMethod, mixin("T." ~ m)))
static assert (false, "Method " ~ methodName ~ " is virtual but not marked as @virtual");
            }
        }
    }

    else
    {
        foreach (m ; __traits(allMembers, T))
        {
            mixin("alias " ~ m ~ " member;");
            static if (is(member == class))
                checkVirtual!(member);
        }
    }

}

--
/Jacob Carlborg

Reply via email to