December 11, 2006 TypeInfo for arrays seem wrong | ||||
---|---|---|---|---|
| ||||
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. |
Copyright © 1999-2021 by the D Language Foundation