www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Subtyping with "alias this" doesn't mix with regular inheritance

reply Stanislav Blinov <stanislav.blinov gmail.com> writes:
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 
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
parent Stanislav Blinov <stanislav.blinov gmail.com> writes:
Oh hell! It took this posting to realize the problem in full. Sorry for 
Dec 27 2010