Subtyping with "alias this" doesn't mix with regular inheritance (issues 5380)
Stanislav Blinov
stanislav.blinov at gmail.com
Mon Dec 27 18:05:45 PST 2010
Copied from bugzilla:
--- Comment #0 from Max Samukha <samukha at voliacable.com> 2010-12-27
03:59:11 PST ---
class A
{
}
class B
{
A a;
alias a this;
}
class C : B
{
}
void main()
{
A a = new C; // error
}
Error: cannot implicitly convert expression (new C) of type test.C to test.A
Since C is a subtype of B (via inheritance) and B is a subtype of A (via
"alias
this"), C should be implicitly convertible to A.
--- Comment #1 from Walter Bright <bugzilla at digitalmars.com> 2010-12-27
13:33:28 PST ---
Yes, I see the problem. Never thought of that.
---
I must say after a long thought I *may* see the problem too, but...
Would you guys mind explaining what should this mean? How is it inferred
that C should be "implicitly" convertible to A in this case? I see a way
of substituting the *existing* reference, but construction? What if B or
C aren't visible during compilation (e.g. are introduced later in a
separate shared library)?
More information about the Digitalmars-d
mailing list