isbaseof.d revision 1.1.1.1
1// https://issues.dlang.org/show_bug.cgi?id=20178 2 3interface I {} 4interface J : I {} 5interface K(T) {} 6class C1 : I {} 7class C2 : C1 {} 8class C3 : J {} 9class C4(T) : C3, K!T {} 10class C5(T) : C4!T {} 11 12void main() @nogc nothrow pure @safe 13{ 14 assert(typeid(C1).isBaseOf(typeid(C1))); 15 assert(typeid(C1).isBaseOf(typeid(C2))); 16 17 assert(!typeid(C2).isBaseOf(typeid(C1))); 18 assert(typeid(C2).isBaseOf(typeid(C2))); 19 20 assert(!typeid(C1).isBaseOf(typeid(Object))); 21 assert(!typeid(C2).isBaseOf(typeid(Object))); 22 assert(typeid(Object).isBaseOf(typeid(C1))); 23 assert(typeid(Object).isBaseOf(typeid(C2))); 24 25 assert(typeid(I).isBaseOf(typeid(I))); 26 assert(typeid(I).isBaseOf(typeid(J))); 27 assert(typeid(I).isBaseOf(typeid(C1))); 28 assert(typeid(I).isBaseOf(typeid(C2))); 29 assert(typeid(I).isBaseOf(typeid(C3))); 30 assert(!typeid(I).isBaseOf(typeid(Object))); 31 32 assert(!typeid(J).isBaseOf(typeid(I))); 33 assert(typeid(J).isBaseOf(typeid(J))); 34 assert(!typeid(J).isBaseOf(typeid(C1))); 35 assert(!typeid(J).isBaseOf(typeid(C2))); 36 assert(typeid(J).isBaseOf(typeid(C3))); 37 assert(!typeid(J).isBaseOf(typeid(Object))); 38 39 assert(typeid(C4!int).isBaseOf(typeid(C5!int))); 40 assert(typeid(K!int).isBaseOf(typeid(C5!int))); 41 assert(!typeid(C4!Object).isBaseOf(typeid(C5!int))); 42 assert(!typeid(K!Object).isBaseOf(typeid(C5!int))); 43 44 static assert(!__traits(compiles, TypeInfo.init.isBaseOf(typeid(C1)))); 45 static assert(!__traits(compiles, typeid(C1).isBaseOf(TypeInfo.init))); 46} 47