[Issue 20080] [2.087.0] Function overloads defined in mixin not callable
    d-bugmail at puremagic.com 
    d-bugmail at puremagic.com
       
    Wed Jul 24 12:02:00 UTC 2019
    
    
  
https://issues.dlang.org/show_bug.cgi?id=20080
Simen Kjaeraas <simen.kjaras at gmail.com> changed:
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |simen.kjaras at gmail.com
         Resolution|---                         |DUPLICATE
--- Comment #1 from Simen Kjaeraas <simen.kjaras at gmail.com> ---
This is by design, and can easily be fixed with an alias:
mixin template Thing( )
{
    public void writeAThing( float val )
    {
        import std.stdio : writeln;
        writeln( val );
    }
}
struct ProperThing
{
    public void writeAThing( int val )
    {
        import std.stdio : writeln;
        writeln( val );
    }
    // Note that we must give the mixin a name:
    mixin Thing!() f;
    // Then this line adds it to the overload set:
    alias f.writeAThing writeAThing;
}
void main
{
    ProperThing thing;
    thing.writeAThing( 42.0f );
}
It's even possible to automate this with reflection:
string aliasAll(alias sym)()
{
    enum symName = __traits(identifier, sym);
    string result = "";
    foreach (e; __traits(allMembers, sym))
        result ~= "alias "~symName~"."~e~" "~e~";";
    return result;
}
And you'd use it like this:
    mixin Thing!() f;
    mixin(aliasAll!f);
*** This issue has been marked as a duplicate of issue 2157 ***
--
    
    
More information about the Digitalmars-d-bugs
mailing list