This is related to casts of arrays not being documented: http://d.puremagic.com/issues/show_bug.cgi?id=2494 The issue is that the following produce different results: const short[] ct = cast(short[]) [cast(byte)1, 1]; // ct is [1, 1] short[] rt = cast(short[]) [cast(byte)1, 1].dup; // rt is [ 257 ] The runtime cast seems to be defined as 'reinterpret the data as an array of a different type, recompute the length' whereas the compile time cast seems to be 'convert each element to the other element type, keep length unchanged'.
You're right, this is a documentation issue. Casts of array literals are treated differently.
While you're at it, could you also document these casts for string literals? short[] ct1 = cast(short[]) "\x01\x01"; // [ 257 ] short[] ct2 = cast(short[]) [cast(char)1, 1]; // [1, 1] even though both literals represent the same char[2] value.
So [cast(byte)1, 1] isn't a byte[], an int[] or anything like that, but of an internal 'array literal' type. Then why is [cast(byte)1, 1].dup not also of this internal 'array literal' type?
Fixed DMD2.023 and DMD1.039
AltStyle によって変換されたページ (->オリジナル) / アドレス: モード: デフォルト 音声ブラウザ ルビ付き 配色反転 文字拡大 モバイル