This should compile:
interface I
{
I foo();
alias foo bar;
}
class C : I
{
C foo() { return this; }
}
void main()
{
auto c = new C;
c = c.bar();
}
But it doesn't, because for some reason, the compiler inserts a cast:
Error: cannot implicitly convert expression ((cast(I)c).foo()) of type aliascovariance.I to aliascovariance.C
Change I to a class, and the error is even more weird:
Error: cannot implicitly convert expression (c.foo()) of type aliascovariance.I to aliascovariance.C
As a workaround, you can repeat the alias in the derived class.
Comment #1 by robert.schadek — 2024-12-13T17:52:20Z