digitalmars.D - Subtyping with "alias this" doesn't mix with regular inheritance
- Stanislav Blinov (32/32) Dec 27 2010 Copied from bugzilla:
- Stanislav Blinov (2/2) Dec 27 2010 Oh hell! It took this posting to realize the problem in full. Sorry for
Copied from bugzilla: --- Comment #0 from Max Samukha <samukha 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 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)?
Dec 27 2010
Oh hell! It took this posting to realize the problem in full. Sorry for disturbance.
Dec 27 2010