digitalmars.D.bugs - TypeInfo for arrays seem wrong
- Chris Miller (26/26) Dec 11 2006 if(cast(TypeInfo_Array)typeid(char[]))
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 =3D 0; i !=3D _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[]) =3D=3D _arguments[i]) will work is b= ecause = the toString() are both "char[]" which is what =3D=3D on TypeInfo compar= es. Solution: typeid(char[]) should be TypeInfo_Aa, and TypeInfo_Aa should = derive from TypeInfo_Array. This goes for the other array types as well.=
Dec 11 2006