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())
Comment #1 by github-bugzilla — 2012-11-12T23:38:30Z
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.
Comment #6 by github-bugzilla — 2012-11-13T21:29:19Z
(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.