www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - D thinks it is OK to mess around with TypeInfo

reply Yuxuan Shui <yshuiv7 gmail.com> writes:
For example

struct A{}
 safe void main(){
	import std.stdio;
	A a, b;
	auto y = typeid(a);
	y.name = "Nope, I'm not A";
	auto x = typeid(b);
	writeln(x);
}

Make changes to TypeInfo will affect all the future typeid() 
results! And D is OK with that?

IMO, TypeInfo returned by typeid() should be immutable.
Mar 04 2016
parent Rikki Cattermole <alphaglosined gmail.com> writes:
On 05/03/16 10:35 AM, Yuxuan Shui wrote:
 For example

 struct A{}
  safe void main(){
      import std.stdio;
      A a, b;
      auto y = typeid(a);
      y.name = "Nope, I'm not A";
      auto x = typeid(b);
      writeln(x);
 }

 Make changes to TypeInfo will affect all the future typeid() results!
 And D is OK with that?

 IMO, TypeInfo returned by typeid() should be immutable.
Yeah TypeInfo and friends needs a lot of work done to it. But that means modifying the compiler + druntime.
Mar 04 2016