TypeInfo of arrays of basic types.
Eldar Insafutdinov
e.insafutdinov at gmail.com
Sat Mar 31 17:08:04 PDT 2012
I was playing around with Variant and came across a very annoying
problem:
auto str_arr = Variant(["1", "2", "3"]);
assert(cast(TypeInfo_Array)str_arr.type(), "This is fine");
auto int_arr = Variant([1, 2, 3]);
assert(cast(TypeInfo_Array)int_arr.type(), "This is broken");
While TypeInfo object of string[] is a TypeInfo_Array instance,
TypeInfo of int[] isn't. Much to my surprise I found out that
TypeInfo of int[] is a mysterious class TypeInfo_Ai and is
actually a subclass of TypeInfo_Class:
writefln("typeinfo of int[]: %s",
typeid(int[]).classinfo.toString());
writefln("base class of typeinfo int[] %s",
typeid(int[]).classinfo.base.classinfo);
// Outputs
typeinfo of int[]: TypeInfo_Ai
base class of typeinfo int[]: TypeInfo_Class
Googling didn't yield any relevant discussions, so I posted it
here, although I'm pretty sure someone should have come across
the problem in the past. Is this a fundamental issue with the
runtime and compiler or is it a bug that can be fixed without
breaking too much?
More information about the Digitalmars-d
mailing list