[Issue 16357] New: cast(T[])[x] casts x to T instead of [x] to T[]
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Sat Aug 6 17:21:17 PDT 2016
https://issues.dlang.org/show_bug.cgi?id=16357
Issue ID: 16357
Summary: cast(T[])[x] casts x to T instead of [x] to T[]
Product: D
Version: D2
Hardware: All
OS: All
Status: NEW
Keywords: wrong-code
Severity: normal
Priority: P3
Component: dmd
Assignee: nobody at puremagic.com
Reporter: thecybershadow at gmail.com
////////////// test.d //////////////
void main()
{
uint x;
ubyte[] data = cast(ubyte[])[x];
assert(data.length == 4);
}
////////////////////////////////////
This is surprising, because if the expression is split up into:
auto arr = [x];
ubyte[] data = cast(ubyte[])arr;
then the result is as expected (an array with 4 elements).
--
More information about the Digitalmars-d-bugs
mailing list