[Issue 13833] .classinfo.name (and typeid(obj)) does not print proper dynamic type when using an interface

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Tue Jul 21 00:03:55 PDT 2015


https://issues.dlang.org/show_bug.cgi?id=13833

Kenji Hara <k.hara.pg at gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|.classinfo.name (and        |.classinfo.name (and
                   |typeid(obj)) does not print |typeid(obj)) does not print
                   |proper dynamic type when    |proper dynamic type when
                   |using a templated interface |using an interface

--- Comment #2 from Kenji Hara <k.hara.pg at gmail.com> ---
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.

--


More information about the Digitalmars-d-bugs mailing list