TypeInfo for arrays seem wrong
Chris Miller
chris at dprogramming.com
Mon Dec 11 14:49:09 PST 2006
if(cast(TypeInfo_Array)typeid(char[]))
writefln("match");
if(cast(TypeInfo_Array)typeid(typeof("hi")))
writefln("match");
Everything's fine so far; it prints match twice. But try this from a
variadic function and it's no longer true:
void foo(...)
{
int i;
for(i = 0; i != _arguments.length; i++)
{
if(cast(TypeInfo_Array)_arguments[i])
writefln("%s matches", i);
}
void main()
{
foo(42, "hello", cast(char[])"world");
}
and it does not match. The type of _arguments[1] ends up being TypeInfo_Aa.
The only reason why (typeid(char[]) == _arguments[i]) will work is because
the toString() are both "char[]" which is what == on TypeInfo compares.
Solution: typeid(char[]) should be TypeInfo_Aa, and TypeInfo_Aa should
derive from TypeInfo_Array. This goes for the other array types as well.
More information about the Digitalmars-d-bugs
mailing list