Bug 9008 – Another forward referencing bug

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
Windows
Creation time
2012-11-12T07:36:00Z
Last change time
2013-11-22T00:22:58Z
Assigned to
nobody
Creator
turkeyman

Comments

Comment #0 by turkeyman — 2012-11-12T07:36:29Z
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
Comment #2 by github-bugzilla — 2012-11-12T23:38:55Z
Comment #3 by bugzilla — 2012-11-12T23:39:45Z
Ignore these "fixes", they were for bug 7220.
Comment #4 by github-bugzilla — 2012-11-13T02:42:17Z
Comment #5 by turkeyman — 2012-11-13T06:24:00Z
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
Comment #7 by yebblies — 2013-01-12T20:01:20Z
Is this fixed now?
Comment #8 by turkeyman — 2013-01-13T00:52:18Z
(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.