Re: typeid, typeinfo, classinfo not returning most derived

2019-06-06 Thread Adam D. Ruppe via Digitalmars-d-learn

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.


typeid, typeinfo, classinfo not returning most derived

2019-06-06 Thread Amex via Digitalmars-d-learn
-		x	0x004b71e0 {Interface for main.I} {m_init={length=0 
ptr=0x}, name="main.I", vtbl={length=0 ptr=0x}, 
...}	object.TypeInfo_Class {TypeInfo_Class}

[TypeInfo_Class]D0006: Error: Type resolve failed   
m_init  {length=0 ptr=0x}   byte[]
+   name"main.I"  string
vtbl{length=0 ptr=0x}   void*[]
interfaces  {length=0 ptr=0x}   
object.Interface[]
base0x  object.TypeInfo_Class
destructor  0x  void*
classInvariant  0x  void function(object.Object)*
m_flags 36  uint
deallocator 0x  void*
m_offTi {length=0 ptr=0x}   object.OffsetTypeInfo[]
defaultConstructor  0x  void 
function(object.Object)*
m_RTInfo0x  const(void)*
-		i	0x004b71e0 {Interface for main.I} {m_init={length=0 
ptr=0x}, name="main.I", vtbl={length=0 ptr=0x}, 
...}	object.TypeInfo_Class {TypeInfo_Class}

[TypeInfo_Class]D0006: Error: Type resolve failed   
m_init  {length=0 ptr=0x}   byte[]
+   name"main.I"  string
vtbl{length=0 ptr=0x}   void*[]
interfaces  {length=0 ptr=0x}   
object.Interface[]
base0x  object.TypeInfo_Class
destructor  0x  void*
classInvariant  0x  void function(object.Object)*
m_flags 36  uint
deallocator 0x  void*
m_offTi {length=0 ptr=0x}   object.OffsetTypeInfo[]
defaultConstructor  0x  void 
function(object.Object)*
m_RTInfo0x  const(void)*
-		c	0x004b71e0 {Interface for main.I} {m_init={length=0 
ptr=0x}, name="main.I", vtbl={length=0 ptr=0x}, 
...}	object.TypeInfo_Class {TypeInfo_Class}

[TypeInfo_Class]D0006: Error: Type resolve failed   
m_init  {length=0 ptr=0x}   byte[]
+   name"main.I"  string
vtbl{length=0 ptr=0x}   void*[]
interfaces  {length=0 ptr=0x}   
object.Interface[]
base0x  object.TypeInfo_Class
destructor  0x  void*
classInvariant  0x  void function(object.Object)*
m_flags 36  uint
deallocator 0x  void*
m_offTi {length=0 ptr=0x}   object.OffsetTypeInfo[]
defaultConstructor  0x  void 
function(object.Object)*
m_RTInfo0x  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)