how is this considered hiding methods?
    Andrej Mitrovic 
    andrej.mitrovich at gmail.com
       
    Sat Sep 22 01:38:40 PDT 2012
    
    
  
On 9/22/12, Andrej Mitrovic <andrej.mitrovich at gmail.com> wrote:
> using the alias
But I do think this can be further improved in the language. Take this
for example:
import std.stdio;
class Foo
{
    void meth(double) { writeln("Foo.meth"); }
}
class Bar : Foo
{
    alias super.meth meth;
    void meth(int) { writeln("Bar.meth"); }
}
class Doo : Bar
{
    alias super.meth meth;
    void meth(long) { writeln("Doo.meth"); }
}
void main()
{
    auto doo = new Doo;
    doo.meth(1);  // calls Bar.meth
}
Now let's say the Doo clas removes the meth overload and the alias:
class Foo
{
    void meth(double) { writeln("Foo.meth"); }
}
class Bar : Foo
{
    // gone
}
class Doo : Bar
{
    alias super.meth meth;
    void meth(long) { writeln("Doo.meth"); }
}
void main()
{
    auto doo = new Doo;
    doo.meth(1);   // now calls Doo.meth
}
We might have wanted the "super alias" in Doo to only work against the
Bar base class so the compiler can notify us if Doo.meth is removed.
The language doesn't have a way to warn us of this.
I would prefer if "super.alias" meant to take overloads of all base
classes into account and that we could use "ClassName.alias" to only
import the overload set of a specific base class. That way this would
trigger a CT error:
class Foo
{
    void meth(double) { writeln("Foo.meth"); }
}
class Bar : Foo
{
}
class Doo : Bar
{
    alias Bar.meth meth;  // error: no overload set in Bar
    void meth(long) { writeln("Doo.meth"); }
}
    
    
More information about the Digitalmars-d-learn
mailing list