This works, and is a very useful trick: struct Foo {uint f;} void main(){ Foo a; ubyte[] b = cast(ubyte[4])a; } However, the following generates an error: void main(){ uint a; ubyte[] b = cast(ubyte[4])a; } The error: Error: e2ir: cannot cast a of type uint to type ubyte[4u]
A report for e2ir ICE from original testcase: Issue 11484
From the past, DMD glue layer does not support a cast from primitive type to static array. And from 2.065, it's changed to semantic error. Therefore, the rejection is intentional. Downgrade to enhancement issue.
*** Issue 7328 has been marked as a duplicate of this issue. ***
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/18345 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB