----- module test; import std.stdio; interface I(T) { } class D : I!(int) { } void main() { I!(int) i = new D; writeln(i.classinfo.name); writeln(typeid(i)); // ditto } ----- Prints: test.I!(int).I It should print: test.D
This bug affects both D1 and D2.
The issue also happens with non-template interface. interface I { } class D : I { } void main() { I i = new D; writeln(typeid(i)); writeln(i.classinfo.name); // ditto } Currently typeid() on interface reference returns the TypeInfo of "most derived" implemented interface. import std.stdio; interface I {} interface J : I {} interface K : I {} class E : J, K {} void main() { E e = new E; J j = e; K k = e; I ij = j; I ik = k; writeln(typeid(ij)); // prints 'test.J' writeln(typeid(ik)); // prints 'test.K' } The interface references ij an ik point different positions of class instance e, so the two typeid()s also return different TypeInfo objects.
Being pedantic, the spec does not state what happens when the static type of the expression is an interface. In fact it says that "if the type is a class, it returns the TypeInfo of the dynamic type (i.e. the most derived type)". But the current behaviour is certainly a bug, and very confusing when encountered. See for example http://forum.dlang.org/thread/gdjaoxypicsxlfvzwbvt@forum.dlang.org This is worth a bugfix in both the implementation and the documentation.
the compiler could prolly just auto-cast to object then typeid it