digitalmars.D.learn - typeid, typeinfo, classinfo not returning most derived
- Amex (76/76) Jun 06 2019 - x 0x004b71e0 {Interface for main.I} {m_init={length=0
- Adam D. Ruppe (9/10) Jun 06 2019 It is a bizarre quirk, I think because interfaces do not
- x 0x004b71e0 {Interface for main.I} {m_init={length=0
ptr=0x00000000}, name="main.I", vtbl={length=0 ptr=0x00000000},
...} object.TypeInfo_Class {TypeInfo_Class}
[TypeInfo_Class] D0006: Error: Type resolve failed
m_init {length=0 ptr=0x00000000} byte[]
+ name "main.I" string
vtbl {length=0 ptr=0x00000000} void*[]
interfaces {length=0 ptr=0x00000000} object.Interface[]
base 0x00000000 object.TypeInfo_Class
destructor 0x00000000 void*
classInvariant 0x00000000 void function(object.Object)*
m_flags 36 uint
deallocator 0x00000000 void*
m_offTi {length=0 ptr=0x00000000} object.OffsetTypeInfo[]
defaultConstructor 0x00000000 void function(object.Object)*
m_RTInfo 0x00000000 const(void)*
- i 0x004b71e0 {Interface for main.I} {m_init={length=0
ptr=0x00000000}, name="main.I", vtbl={length=0 ptr=0x00000000},
...} object.TypeInfo_Class {TypeInfo_Class}
[TypeInfo_Class] D0006: Error: Type resolve failed
m_init {length=0 ptr=0x00000000} byte[]
+ name "main.I" string
vtbl {length=0 ptr=0x00000000} void*[]
interfaces {length=0 ptr=0x00000000} object.Interface[]
base 0x00000000 object.TypeInfo_Class
destructor 0x00000000 void*
classInvariant 0x00000000 void function(object.Object)*
m_flags 36 uint
deallocator 0x00000000 void*
m_offTi {length=0 ptr=0x00000000} object.OffsetTypeInfo[]
defaultConstructor 0x00000000 void function(object.Object)*
m_RTInfo 0x00000000 const(void)*
- c 0x004b71e0 {Interface for main.I} {m_init={length=0
ptr=0x00000000}, name="main.I", vtbl={length=0 ptr=0x00000000},
...} object.TypeInfo_Class {TypeInfo_Class}
[TypeInfo_Class] D0006: Error: Type resolve failed
m_init {length=0 ptr=0x00000000} byte[]
+ name "main.I" string
vtbl {length=0 ptr=0x00000000} void*[]
interfaces {length=0 ptr=0x00000000} object.Interface[]
base 0x00000000 object.TypeInfo_Class
destructor 0x00000000 void*
classInvariant 0x00000000 void function(object.Object)*
m_flags 36 uint
deallocator 0x00000000 void*
m_offTi {length=0 ptr=0x00000000} object.OffsetTypeInfo[]
defaultConstructor 0x00000000 void function(object.Object)*
m_RTInfo 0x00000000 const(void)*
Simply for the code
auto info(T)(T o)
{
auto x = typeid(o);
auto i = x.typeinfo;
auto c = o.classinfo;
return;
}
info exists in it's own module called from the main module.
interface I
{
void foo();
}
abstract class A : I
{
}
class C : A
{
void foo()
{
writeln("x");
}
}
class D : C { }
and
I i = new D();
info(i);
(more or less)
Jun 06 2019
On Thursday, 6 June 2019 at 20:22:00 UTC, Amex wrote:I i = new D();It is a bizarre quirk, I think because interfaces do not necessarily point to objects with RTTI (though this can be statically determined, so I am not sure that is valid), but when you do typeid on an interface, it gives the typeinfo for that interface, not the object itself. First cast to Object, then get the typeid and you'll see what you want to see. maybe we should just change this behavior.
Jun 06 2019








Adam D. Ruppe <destructionator gmail.com>