Thread overview
[Issue 9008] New: Another forward referencing bug
Nov 12, 2012
Manu
Nov 13, 2012
Walter Bright
Nov 13, 2012
Manu
Jan 13, 2013
yebblies
Jan 13, 2013
Manu
November 12, 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@puremagic.com
        ReportedBy: turkeyman@gmail.com


--- Comment #0 from Manu <turkeyman@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: -------
November 13, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=9008



--- Comment #1 from github-bugzilla@puremagic.com 2012-11-12 23:38:30 PST ---
Commit pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/ce0d593659ec80ce5a6e626bc9d663660dd74451 fix Issue 9008 - Another forward referencing bug

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
November 13, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=9008



--- Comment #2 from github-bugzilla@puremagic.com 2012-11-12 23:38:55 PST ---
Commit pushed to dmd-1.x at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/1a2efd2a555604dfb6d19adf3899efa5dff49011 fix Issue 9008 - Another forward referencing bug

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
November 13, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=9008


Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bugzilla@digitalmars.com


--- Comment #3 from Walter Bright <bugzilla@digitalmars.com> 2012-11-12 23:39:45 PST ---
Ignore these "fixes", they were for bug 7220.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
November 13, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=9008



--- Comment #4 from github-bugzilla@puremagic.com 2012-11-13 02:42:17 PST ---
Commit pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/cc91b4baa0761a8c4e1ba4fd7513a30f8bc9a3fe fix Issue 9008 - Another forward referencing bug

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
November 13, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=9008



--- Comment #5 from Manu <turkeyman@gmail.com> 2012-11-13 06:24:00 PST ---
Just tried it out, this fix silences the forward reference error message, but the situation is replaced by a new problem...

The foreach over getOverloads only iterates once for the first overload in the
series.
Uncommenting the same lines that made the problem go away before causes all
overloads to be iterated as expected.

It's basically the same problem, just manifesting differently.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
November 14, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=9008



--- Comment #6 from github-bugzilla@puremagic.com 2012-11-13 21:29:19 PST ---
Commit pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/64a2aa2a901633ac246a391a0a6ec46b2db2a096 supplemental fix for issue 9008

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
January 13, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=9008


yebblies <yebblies@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |yebblies@gmail.com


--- Comment #7 from yebblies <yebblies@gmail.com> 2013-01-13 15:01:20 EST ---
Is this fixed now?

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
January 13, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=9008



--- Comment #8 from Manu <turkeyman@gmail.com> 2013-01-13 00:52:18 PST ---
(In reply to comment #7)
> Is this fixed now?

Try my code from the top. If it compiles without error, then yes.

Sorry, I'm not near any computers for a few weeks.

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