[Issue 14612] typeid(interface) returns TypeInfo_Class object

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Sun Jul 5 10:20:33 PDT 2015


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

Rainer Schuetze <r.sagitario at gmx.de> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |r.sagitario at gmx.de

--- Comment #2 from Rainer Schuetze <r.sagitario at gmx.de> ---
The language spec says for both typeid() and .classinfo that the dynamic type
is returned. For classinfo, it says ".classinfo applied to an interface gives
the information for the interface, not the class it might be an instance of."
which makes it a compile time property for interfaces. I could not find a spec
for typeid regarding interfaces.

I suspect they are supposed to be the same. That means typeid(i) and
i.classinfo should evaluate to typeid(I). This must be generated by the
compiler.

Actually I think the semantics are pretty arbitrary and not intuitive. Why
would anyone expect J to be the correct type? I'd rather prefer if both classes
and interfaces would return the dynamic type, i.e. typeid(D). You can get the
static type of an expression by using typeid(typeof(i)).

--


More information about the Digitalmars-d-bugs mailing list