www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - typeof(t) not working correctly?

reply %u <wfunction hotmail.com> writes:
Hi,

I'm running this code below, and it returns an array of length zero for both
print statements. Is this a bug, or am I missing something?

Thank you!



private import std.stdio;
private import std.traits;

class Temp
{
	public int base1;
	public void foo() { writeln("foo base called"); }
}

class Temp2 : Temp
{
	public int derived1;
	public override void foo() { writeln("foo derived called"); }
}

void main()
{
	Temp t = new Temp2();
	writeln(typeid(t).offTi().length); //Prints 0
	writeln(typeid(t).getMembers(null).length); //Prints 0
}
Dec 26 2010
parent reply "Robert Jacques" <sandford jhu.edu> writes:
On Sun, 26 Dec 2010 22:48:42 -0700, %u <wfunction hotmail.com> wrote:

 Hi,

 I'm running this code below, and it returns an array of length zero for  
 both
 print statements. Is this a bug, or am I missing something?

 Thank you!



 private import std.stdio;
 private import std.traits;

 class Temp
 {
 	public int base1;
 	public void foo() { writeln("foo base called"); }
 }

 class Temp2 : Temp
 {
 	public int derived1;
 	public override void foo() { writeln("foo derived called"); }
 }

 void main()
 {
 	Temp t = new Temp2();
 	writeln(typeid(t).offTi().length); //Prints 0
 	writeln(typeid(t).getMembers(null).length); //Prints 0
 }

typeid is working correctly, (it simply returns the TypeInfo for a type), but it is a well known issue that the offset type info array is not populated. It is bug 1348 (http://d.puremagic.com/issues/show_bug.cgi?id=1348). You can vote it up in Bugzilla if you'd like. In general, questions like this should be sent to D.learn, and I also generally recommend doing a quick search in Bugzilla just to see if you get a hit against a known issue.
Dec 26 2010
next sibling parent %u <wfunction hotmail.com> writes:
Oh wow, I should've looked beforehand -- thank you very much for the great
reply,
and sorry for not searching first!! :)
Dec 27 2010
prev sibling parent Jacob Carlborg <doob me.com> writes:
On 2010-12-27 08:31, Robert Jacques wrote:
 On Sun, 26 Dec 2010 22:48:42 -0700, %u <wfunction hotmail.com> wrote:

 Hi,

 I'm running this code below, and it returns an array of length zero
 for both
 print statements. Is this a bug, or am I missing something?

 Thank you!



 private import std.stdio;
 private import std.traits;

 class Temp
 {
 public int base1;
 public void foo() { writeln("foo base called"); }
 }

 class Temp2 : Temp
 {
 public int derived1;
 public override void foo() { writeln("foo derived called"); }
 }

 void main()
 {
 Temp t = new Temp2();
 writeln(typeid(t).offTi().length); //Prints 0
 writeln(typeid(t).getMembers(null).length); //Prints 0
 }

typeid is working correctly, (it simply returns the TypeInfo for a type), but it is a well known issue that the offset type info array is not populated. It is bug 1348 (http://d.puremagic.com/issues/show_bug.cgi?id=1348). You can vote it up in Bugzilla if you'd like. In general, questions like this should be sent to D.learn, and I also generally recommend doing a quick search in Bugzilla just to see if you get a hit against a known issue.

Neither is the array that getMembers returns. -- /Jacob Carlborg
Dec 27 2010