TypeInfo of arrays of basic types.

H. S. Teoh hsteoh at quickfur.ath.cx
Sat Mar 31 22:31:43 PDT 2012


On Sun, Apr 01, 2012 at 02:08:04AM +0200, Eldar Insafutdinov wrote:
> 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:

I've seen this before. TypeInfo_Ai is apparently some kind of built-in
typeinfo that's handled separately from TypeInfo_Array. Many arrays of
built-in types have their own typeinfo's this way; it seems
TypeInfo_Array is only used in the more general case.

I don't know compiler internals to know why things are this way, but
I've definitely seen problems caused by this split between specific TI's
and general TI's (e.g., the fact that getHash() of char[] and
immutable(char)[] (i.e., string) is inconsistent with the getHash() of
const(char)[]).


T

-- 
Valentine's Day: an occasion for florists to reach into the wallets of
nominal lovers in dire need of being reminded to profess their
hypothetical love for their long-forgotten.


More information about the Digitalmars-d mailing list