Thread overview
[Issue 13833] .classinfo.name (and typeid(obj)) does not print proper dynamic type when using a templated interface
Dec 08, 2014
Andrej Mitrovic
[Issue 13833] .classinfo.name (and typeid(obj)) does not print proper dynamic type when using an interface
Jul 21, 2015
Kenji Hara
Sep 04, 2016
Lodovico Giaretta
Jan 26, 2021
Adam D. Ruppe
Dec 17, 2022
Iain Buclaw
December 08, 2014
https://issues.dlang.org/show_bug.cgi?id=13833

--- Comment #1 from Andrej Mitrovic <andrej.mitrovich@gmail.com> ---
This bug affects both D1 and D2.

--
June 09, 2015
https://issues.dlang.org/show_bug.cgi?id=13833

Andrei Alexandrescu <andrei@erdani.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Version|D1 & D2                     |D2

--
July 21, 2015
https://issues.dlang.org/show_bug.cgi?id=13833

Kenji Hara <k.hara.pg@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@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.

--
September 04, 2016
https://issues.dlang.org/show_bug.cgi?id=13833

Lodovico Giaretta <lodovico@giaretart.net> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |lodovico@giaretart.net

--- Comment #3 from Lodovico Giaretta <lodovico@giaretart.net> ---
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.

--
January 26, 2021
https://issues.dlang.org/show_bug.cgi?id=13833

Adam D. Ruppe <destructionator@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |destructionator@gmail.com

--- Comment #4 from Adam D. Ruppe <destructionator@gmail.com> ---
the compiler could prolly just auto-cast to object then typeid it

--
December 17, 2022
https://issues.dlang.org/show_bug.cgi?id=13833

Iain Buclaw <ibuclaw@gdcproject.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P1                          |P3

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

--- Comment #5 from dlangBugzillaToGithub <robert.schadek@posteo.de> ---
THIS ISSUE HAS BEEN MOVED TO GITHUB

https://github.com/dlang/dmd/issues/18921

DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB

--