[Issue 9008] New: Another forward referencing bug

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Nov 12 07:36:30 PST 2012


http://d.puremagic.com/issues/show_bug.cgi?id=9008

           Summary: Another forward referencing bug
           Product: D
           Version: D2
          Platform: All
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody at puremagic.com
        ReportedBy: turkeyman at gmail.com


--- Comment #0 from Manu <turkeyman at gmail.com> 2012-11-12 07:36:29 PST ---
Rather complex situation, I couldn't boil it down anymore...
Note the 2 commented lines; uncommenting these lines will make it work properly
(this is my work-around)
For some reason, scanning over each of the overloads in advance stops the
forward reference error.

This is tested using DMD-Win64.


template TestHasAttribute( alias symbol, Attribute )
{
    template Impl( A... )
    {
        static if( A.length == 0 )
            enum bool Impl = false;
        else static if( is( typeof( A[0] ) == Attribute ) )
            enum bool Impl = true;
        else
            enum bool Impl = Impl!( A[1..$] );
    }

    alias Impl!( __traits( getAttributes, symbol ) ) TestHasAttribute;
}

string generateImportStubs( alias reference )()
{
    string text;

    foreach( m; __traits( allMembers, reference ) )
    {
        // scan for functions...
        static if( is( typeof( mixin( m ) ) ) && is( typeof( mixin( m ) ) ==
function ) )
        {
            // uncomment these lines, and the bug disappears
//                foreach( i, overload; __traits( getOverloads, reference, m )
)
//                    enum nothing = typeof(overload).stringof;

            foreach( i, overload; __traits( getOverloads, reference, m ) )
            {
                static if( TestHasAttribute!( overload, int ) )
                    text ~= ""; // mixin some stuff, irrelevant to the bug...
            }
        }
    }

    return text;
}

import std.traits;
mixin( "alias " ~ moduleName!generateImportStubs ~ " TestThisModule;" );
mixin( generateImportStubs!( TestThisModule )() );

private:
// overloads cause errors
void overload();
void overload( int x );


test.d(124): Error: template instance remedy.test.TestHasAttribute!(overload,
int) forward reference of overload
test.d(124): Error: template instance remedy.test.TestHasAttribute!(overload,
int) error instantiating
test.d(135):        instantiated from here: generateImportStubs!(test)
test.d(135):        called from here: generateImportStubs()
test.d(135): Error: argument to mixin must be a string, not
(generateImportStubs())

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


More information about the Digitalmars-d-bugs mailing list