std.typecons.Proxy + inheritance breaks cast'ing to inherited type

Lukasz Wrzosek via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Mar 16 02:03:16 PDT 2015


Hello
I was just exploring possibility to mimic multiple inheritance 
from C++ (do not ask why, just for fun).
I've stumbled on below issue (let's say corner case) and most 
likely this is bug in implementation of template Proxy, isn't it ?


import std.typecons;
class IA {}
class IB {}
class C : IB {
   IA a;
   mixin Proxy!a;

   public this() {
     a = new IA;
   }
}

void main() {
   C c = new C;
   IA a = cast(IA)c;
   IB b_ok = c;
   IB b_not_ok = cast(IB)c;
   assert(c !is null);
   assert(a !is null);
   assert(b_ok !is null);
   assert(b_not_ok !is null); //fails
}


More information about the Digitalmars-d-learn mailing list